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.

 

 

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.