Jump to content

Directories


slanton

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]
Link to comment
https://forums.phpfreaks.com/topic/21886-directories/
Share on other sites

Archived

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

×
×
  • Create New...

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.