Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/137060-how-should-i-write-this-if-statemt/
Share on other sites

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)) {

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.