Jump to content


Photo

Directories


  • Please log in to reply
2 replies to this topic

#1 slanton

slanton
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationNew Zealand

Posted 24 September 2006 - 08:09 PM

I want a different database to open depending on where a page is linked from.
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?
<?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");
 }
?>


#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 24 September 2006 - 08:58 PM

Try the standard PHP file_exists function, see http://nl2.php.net/m...file-exists.php.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 slanton

slanton
  • Members
  • PipPip
  • Member
  • 27 posts
  • LocationNew Zealand

Posted 24 September 2006 - 09:21 PM

Thanks....much better!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users