grandman Posted December 15, 2008 Share Posted December 15, 2008 Hello, the 'IF' statement if (file_exists($filename)) { , is just ignored. Wondering have I written a re-direct script. What I want is for the member logging in, if already registered to be taken to their folder. <?php ob_start(); $Database = mysql_connect("localhost", "linkhome_admin", "mummother210"); mysql_select_db("linkhome_link2000"); $fields = mysql_query("SELECT * FROM users"); $Username = mysql_result($fields,0,1,"username"); $dirname = $Username; $filename = "onwards/controler/" . "$dirname"; //below not working if (file_exists($filename)) { //above not working $URL="http://www.linkhomes2000.co.uk/onwards/controler/ " . "$dirname" . "/index.php"; header ("Location: $URL"); } else { mkdir("$filename" . "$dirname", 0777); echo "welcome " . "$dirname" . "Your Area Is Being created."; } chown("$dirname", $linkhome); $handle = opendir("$dirname"); while($entry = readdir($handle)) if($entry != "." && $entry != "..") copy($index.php .$entry, "$dirname " .$index.php .$entry); ob_end_flush(); ?> DG Quote Link to comment https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/ Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 I think you have to actually link to a file not a directory. Try adding that index.php file onto the end of the $filename and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/#findComment-715820 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 I guess you create a directory for every user that signs up? You should keep track of that in a database, or at least a text file. Seeing if a user has already signed up via checking if a file/dir exists is the wrong approach. You should actually check with both. Anyway, if you want to check a directory use: if (is_dir($filename)) { Quote Link to comment https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/#findComment-715829 Share on other sites More sharing options...
MasterACE14 Posted December 15, 2008 Share Posted December 15, 2008 yes you have to link to a file. If you want to see if a directory exists use is_dir(); Regards ACE edit: beat me to it Maq Quote Link to comment https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/#findComment-715830 Share on other sites More sharing options...
grandman Posted December 15, 2008 Author Share Posted December 15, 2008 I guess you create a directory for every user that signs up? You should keep track of that in a database, or at least a text file. Seeing if a user has already signed up via checking if a file/dir exists is the wrong approach. You should actually check with both. Anyway, if you want to check a directory use: if (is_dir($filename)) { Hello, Are you saying that I should have a table in my DB something like user_folder, and as created add them to the table. Then use this to check the existence of a folder. DG Quote Link to comment https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/#findComment-715888 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 Yes. The best way to check if the user exists is via database. 1) If the folder does not exist than the user does not exist? 2) This is the only way you check to see if a user is registered? You should keep track of this through a database. Have the folders named the same as the user/userid whatever is unique. That way you can check to see if they exist in the database, if they do redirect them to there folder, "/root/users/$userid/", that way it's easy to redirect the user to their folder. If they don't exist in the database then do what you want. If they register than enter them into the database and create a folder for them. If you use this method than you can link folders with unique id's (username or userid). IMO, this would be the easiest and most efficient approach. Quote Link to comment https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/#findComment-715894 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.