Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Restricting direct access to an include page

    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

  • #2
    New Coder
    Join Date
    Mar 2007
    Location
    Northern Ireland
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try defining a constant at the top of main.php

    E.g.

    Code:
    define('CONSTANT_NAME', true);
    Then on your include files, right at the top put this

    Code:
    <?php
    if ( !defined('CONSTANT_NAME') )
    {
    	header("location: main.php");
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •