Jump to content

make file readable only when it is included or required else display error404


Regex

Recommended Posts

I how a problem that if someone goes in myurl.../content.php he can see my content.php file but I would like that it could bee seen only  when I include that in myurl.../index.php. How it could be done that if someone goes to myurl.../index.php/content.php he is redirected to error 404 but if I include that file somewhere then it does not redirecting.

 

 

Link to comment
Share on other sites

Have index.php define a constant, and inside content.php check if that constant has been defined. Of not, redirect.

 

Index

<?php
define('IN_INDEX_PHP', true);
include('content.php');
Content

<?php 
if (!defined('IN_INDEX_PHP')){
   header('Location: index.php');
   exit;
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.