require_once and direct script access security

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    require_once and direct script access security

    I read up that sometimes require_once() still will reload a script file or w/e sometimes. Should I do something like this to prevent overhead?
    Code:
    // Script file
    if ( isset(FILE_LIB) ) exit; // Prevent double loading
    
    define('FILE_LIB', 1);
    ...
    ...
    Is this reasonable or no?

    Also, to stop people from accessing ( not using .htaccess ) other scripts then desired, like the above mentioned library file...

    Code:
    // index.php
    define('MY_SCRIPT', 1);
    
    // library.php
    if ( !isset(MY_SCRIPT) ) exit;
    Or should I redirect the user to index.php???
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Where did you read that?

    Also, you should be using defined(), not isset(), to check where a constant is defined.

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      One of the random articles I've been coming accross while researching Good PHP Practices, and PHP security Tricks.

      Comment

      Working...