Forum Moderators: coopster
This is what I have been doing thus far and it seems pretty limited or maybe I'm just not grasping the correct way to do this.
<?$out = fopen("users/$username.php", "a");
if (!$out) {
print("Could not append to file");
exit;
}
fputs ($out,implode,("\n"));
fwrite($out,"
<HTML for the new user page>
");
fclose($out);
?>
You don’t want to create a whole new “page” for each user you just want the content of the page to be specific to the user.
Create a template page that calls to the user database to populate the page content with the user’s preferences.
With a user management system like you are creating this is easiest to achieve with the use of sessions to identify the user.
When your users complete the registration process you want to commit the information to your database so that it can be called back later to display content.
For Example:
Let’s say a user completes the registration process and then they log in to their control panel/profile/etc.
You’ll want to use an assigned unique key (like a user id #) to go get the users information from the database and then load that info into usable variables like (assuming MySQL/PHP)….
<?
$query = “SELECT * FROM users WHERE user_id=’{$_SESSION[‘user_id’]}’”;
$result = mysql_query ($query) or (… -> your error handler here);
if ($result){
//-> Load results
while ($row = mysql_fetch_assoc($result)){
$firstName = $row[‘fname’];
$lastName = $row[‘lname’];
$email = $row[‘email];
etc…
etc…
}
?>
//->You’ll set up a single template page to hold the structure for the information like….
<html>
<body>
<p>First Name: <? echo $firstName;?></p>
<p>Last Name: <? echo $lastName;?></p>
<p>Email: <? echo $email;?></p>
} else {
//-> DB query failed – do something
}
Once you have authenticated the user, then you can have a column in the db that is the user status, and display the content based on that value (ie admin, member, etc...)
Just a note: In the above code, the while loop isn't necessary considering you are only expecting one result.
Also, don't forget to escape your query variables! [us2.php.net]
Best of luck!