Re: check if a file is included
| From: | Jochem Maas | Date: | Mon, 15 Sep 2008 23:38:44 +0000 |
| Subject: | Re: check if a file is included | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280233@lists.php.net to get a copy of this message | ||
ANR Daemon schreef:
Greetings, Jochem Maas. In reply to Your message dated Friday, September 12, 2008, 17:05:58,I like my 'schreef' better.
a, why must it be windows proof, nobody asked for that? b, does this take into account that $_SERVER['SCRIPT_FILENAME'] is not available of some versions of IIS? c, you'd think __FILE__ and $_SERVER['SCRIPT_FILENAME'] used consistent slashes on a given system, no? (I doubt you need to do the funky translation. d, there is no account take for symlinks, if you really want to be pedantic: realpath(__FILE__) != realpath(getenv('PATH_TRANSLATED')) e. the OP wanted it to work on the cmdline as well (sounds silly to me but there you have it) but really this is all madness. put the file outside the webroot OR stick it in a subfolder with a .htaccess containing: Deny From Allactually $_SERVER[script_name] is probably better if not being used from a webserver.you didn't mention wanting to use the cmdline. untested code follows:<?phpfunction indirectCall($s) {Actually, it must be (Windows-proof):if (php_sapi_name() == 'cli') { return strstr($s, $argv[0]) !== false; } else { return strstr($s, $_SERVER["REQUEST_URI"]) !== false; }}
<?php function indirectCall($s) { return (strtr($s, '\\', '/') != strtr($_SERVER['SCRIPT_FILENAME'], '\\', '/')); } if(!indirectCall(__FILE__)) { // we got you there, fool! } ?> For those who do not know: Windows support both back- and forward slashes as directory separators. Since DOS 3.3 at least. Even php.exe -f "//host/share/script.php" works.