The best idea of denied access file directly?

Discussion in 'PHP' started by tonyinabox, Oct 13, 2006.

  1. #1
    I am looking for the idea for php code to denied the accessing directly to a file.

    The file i am talking about will be use for include();

    so basically not allow to access the file directly.

    :)
     
    tonyinabox, Oct 13, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could do something like this:
    <?php
    $green="yes";
    include('yourfile.php');
    ?>
    PHP:
    and in the file yourfile.php have:
    if($green!="yes"){
    exit();
    }
    else
    {
    //do something
    }
    PHP:
    There may be a better/more secure solution depending what you need to do.
     
    mad4, Oct 13, 2006 IP
  3. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it is going to be in opensource project so.

    do you have an idea for more secure?

    I saw in mambo use

    defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
    Code (markup):
    Do you know how does it work?
     
    tonyinabox, Oct 13, 2006 IP
  4. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #4
    oh I on the file will have this line, but still thinking about what to check

    
    //check direct access
    if ($something to check not correct) {
       echo "This file can't access directly";
       exit;
    }
    
    Code (markup):
     
    tonyinabox, Oct 13, 2006 IP
  5. tonyinabox

    tonyinabox Peon

    Messages:
    1,988
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok I know now. hehehe.. very same as the code you gave above. :p

    thank you.
     
    tonyinabox, Oct 13, 2006 IP