Re[2]: check if a file is included

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greetings, Jochem Maas.
In reply to Your message dated Friday, September 12, 2008, 17:05:58,

>> actually $_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:

> <?php

> function indirectCall($s)
> {
>         if (php_sapi_name() == 'cli') {
>                 return strstr($s, $argv[0]) !== false;          
>         } else {
>                 return strstr($s, $_SERVER["REQUEST_URI"]) !== false;
>         }
> }


Actually, it must be (Windows-proof):

<?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.


-- 
Sincerely Yours, ANR Daemon <anrdaemon@xxxxxxxxxxx>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux