Forum Moderators: coopster

Message Too Old, No Replies

User specific content

having trouble

         

modouno

5:29 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



I am trying to create some user specific content (profile,admin, etc..) I have created a register and login script but I am a little lost when it comes to making a user specific page for them when they register (where it can display there info, make changes).

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

?>


This seems to be working ok, but I can't seem to figure out how to also output php in the newly created page. I always seem to get errors. Is there a better, different way to do this?

justgowithit

6:21 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



I think you’re attacking the issue a little off-center. By the looks of things you’re trying to make the “page” dynamic when in fact you want the content to be dynamic.

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

}

eelixduppy

9:37 pm on Nov 2, 2006 (gmt 0)



modouno, you may want to take a look at PHP User Authentication and Passwords [webmasterworld.com] taken from our Library [webmasterworld.com].

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!

modouno

7:21 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



Gotcha.

Cheers!