Jump to content

Archived

This topic is now archived and is closed to further replies.

slanton

Directories

Recommended Posts

I want a different database to open depending on where a page is linked [b]from[/b].
To make sure that no one changes the url I have the following code that ensures that the $name is part of a directory and if not they are sent to a page telling them this. The following code works but I was wondering if there is a more simple way of achieving the same result?
[code]
<?php
$name =$_GET['name'];
$id="../../directory/$name/file.php";
$fd = @opendir("../../directory");
    if($fd) {
      while (($part = @readdir($fd)) == true) {
        if ($part != "." && $part != "..") {
          $file_array[]=$part;
        }
      }
    }
closedir($fd);
if(in_array("$name",$file_array)){
require_once("$id");
}
else{
header("Location:wrong.php");
}
?>
[/code]

Share this post


Link to post
Share on other sites
Try the standard PHP file_exists function, see [url=http://nl2.php.net/manual/en/function.file-exists.php]http://nl2.php.net/manual/en/function.file-exists.php[/url].

Ronald  8)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.