note 60176 added to function.readdir
| From: | info | Date: | Wed, 28 Dec 2005 19:39:09 +0000 |
| Subject: | note 60176 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100881@lists.php.net to get a copy of this message | ||
wrote this piece. I use it to validate my $_GET variables.
It firsts gets the variable $page, cheks if that variable is assinged (on the main index, it is
not).
if it is assinged, it checks if it equals one of the found directory's, and then i assigns the
variable definatly.
this is a rather secure way of validating the $_GET variable, which on my site should only have the
name of one of my directory's.
<?php
$page = $_GET['a'];
if ($page != "" || !empty($page))
{
$handle=opendir('albums');
while (false!==($file = readdir($handle)))
{
if (substr($file,0,1)!=".") //do not look up files or directory's which start
with a dot
{
if(!eregi("thumb",$file)) // all files and dir's containign the word thumb are
filtred out
{
$path = "albums/" . $file;
if(is_dir($path)) // only directory's will get listed
{
if($page != $file) die("wrong argument! only a existing album may be set"); //
validates input
else
{
$page = "albums/" . $page;
$thumb = $page . thumb;
}
}
}
}
}
closedir($handle);
}
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60176
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60176&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60176&report=yes
Search -- http://master.php.net/manage/user-notes.php