slanton Posted September 24, 2006 Share Posted September 24, 2006 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 More sharing options...
ronverdonk Posted September 24, 2006 Share Posted September 24, 2006 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) Link to comment https://forums.phpfreaks.com/topic/21886-directories/#findComment-97758 Share on other sites More sharing options...
slanton Posted September 24, 2006 Author Share Posted September 24, 2006 Thanks....much better!! Link to comment https://forums.phpfreaks.com/topic/21886-directories/#findComment-97765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.