Question

So currently on my member website, I'm doing things the easy way and using the same page for every users profile, just using the $_SESSION code to bring up different user information depending on the current logged in user.

My question is, how would I bring up other users information? Say if I was searching through the members, clicked a name it should bring up their profile, how could I get that working if I don't have separate pages for each member? Any ideas?

No correct solution

OTHER TIPS

My solution is simple.

Let's say, from what you said, you store logged in user ID on $_SESSION and so, you get and use that user ID when you visit the page to fetch the user info from the database, then display it.

Now, here's what I think. Just have a simple IF statement.

$uid = (isset($_GET['uid'])) ? $_GET['uid'] : $_SESSION['uid'];

$query = "SELECT * FROM users WHERE id = $uid";

It gets the ID from the URL if it is set, if not, use the id from the session.

// this is an example of a URL with uid = 12.
http://yourwebsite.com/profile.php?uid=12

So what this does, even if a user is logged in, if s/he visit the page with a uid = n, s/he will see someone else's profile.

And so, you have to append/have uid = n on every link of your user list.

NOTE: That just a quick and simple example, that code isn't good as is. (i.e. security and validation)

Use a post or get variable of the members ID to display a generic "public" member page for each member, then only display the special "private" features to the user who has a matching Session ID to that member ID. You will have to check the member ID against the session ID each time you are about to echo something "private". When he views other members the ID wont match so he will only see their "public" page and vice versa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top