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] Quote Link to comment 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) Quote Link to comment Share on other sites More sharing options...
slanton Posted September 24, 2006 Author Share Posted September 24, 2006 Thanks....much better!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.