note 83705 added to function.realpath
| From: | waldemar dot axdorph at gmail dot com | Date: | Sun, 08 Jun 2008 15:49:54 +0000 |
| Subject: | note 83705 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140242@lists.php.net to get a copy of this message | ||
I made this function so that I could see if a user was trying to go above the current directory.
My top dir:
/var/www/dir/
User wanted
/var/www/
This comes in handy when you're making a php explorer/filemanager and you want your files in
the directory above to be private.
Here it is
<?php
//usage
//$dir is the dir you are in
//$dir_top is the highest dir allowed.
//example
/*
if(above_dir('../', '/var/www/filemgr'))
die('Not allowed. Please stick to your directories');
*/
function above_dir($dir, $dir_top){
if($dir == $dir_top)
return false;
$dir = realpath($dir);
$dir_top = realpath($dir_top);
$dir = count(explode('/', $dir));
$dir_top = count(explode('/', $dir_top));
if($dir <= $dir_top){
return true;
}else{
return false;
}
}
?>
----
Server IP: 212.63.193.10
Probable Submitter: 81.225.116.152
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- https://master.php.net/note/edit/83705
Del: integrated -- https://master.php.net/note/delete/83705/integrated
Del: useless -- https://master.php.net/note/delete/83705/useless
Del: bad code -- https://master.php.net/note/delete/83705/bad+code
Del: spam -- https://master.php.net/note/delete/83705/spam
Del: non-english -- https://master.php.net/note/delete/83705/non-english
Del: in docs -- https://master.php.net/note/delete/83705/in+docs
Del: other reasons-- https://master.php.net/note/delete/83705
Reject -- https://master.php.net/note/reject/83705
Search -- https://master.php.net/manage/user-notes.php