note 36027 added to function.show-source
| From: | wynder at rn2 dot php dot net | Date: | Tue, 23 Sep 2003 12:42:57 +0000 |
| Subject: | note 36027 added to function.show-source | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56971@lists.php.net to get a copy of this message | ||
For security, a great function to use in conjunction with this is basename():
<?php
if ( !empty($_SERVER['argv'][0]) )
{
$f_source = basename($_SERVER['argv'][0], ".inc");
}
else
{
$f_source = "http://".$_SERVER['SERVER_ADDR'].$_SERVER['PHP_SELF'];
}
?>
The url would be: http://localhost/source.php?file.php
If someone tried to play with the query string and did:
http://localhost/source.php?/var/passwd
basename() would chop the argument down to 'passwd' and, in essense, limiting access to
files in the same directory as your source.php file. The optional argument ".inc" allows
you to exclude a single file type -- I think that could've been done a bit better, but
that's my opinion. :)
----
Manual Page -- http://www.php.net/manual/en/function.show-source.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36027
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36027&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36027&report=yes