PDA

View Full Version : [SOLVED] PHP require



emiller12345
May 9th, 2012, 07:11 AM
Is there anyway to tell if a file is being called as a require to another file, or if it is being accessed directly?

Bachstelze
May 9th, 2012, 06:09 PM
Not an expert, but looks like you can use $_SERVER['PHP_SELF'].

emiller12345
May 10th, 2012, 05:19 AM
yes thank you.

("MyPHP.class.php" === basename($_SERVER['PHP_SELF']))this appears to work okay to discriminate the required from non required
edit:
I didn't realize that $_SERVER['PHP_SELF'] variable is "user editable", as such it should probably be run through htmlentites to avoid XSS

("MyPHP.class.php" === basename(htmlentities($_SERVER['PHP_SELF'])))