View Full Version : Restricting direct access to an include page

03-24-2007, 12:06 PM
Hiya guys.

Firstly, thank you for your help on the date() functions, they worked like a dream once i learned them.

I'm having a bit of trouble...i'l give an example below.

I have 2 pages, main.php and include.php.

I have made main.php call include.php and show its contents, but i do not want my visitors to be able to type in www.mydomain.com/include.php and see the contents of the file.

A couple of years back, i remember making a password protection section in PHP, and i think i used a 'if requested, display("restricted area") kind of thing, but i cannot remember.

Could someone just refresh my memory please

03-24-2007, 02:46 PM
Try defining a constant at the top of main.php


define('CONSTANT_NAME', true);

Then on your include files, right at the top put this

if ( !defined('CONSTANT_NAME') )
header("location: main.php");