RJcreatives
RJcreatives

Reputation: 45

User profiles to display info dependant on owner with php

I have set up a basic system where users can sign up, login and view their own profile. However, currently their information is displayed on the profile page using a SESSION variable to store their username. All other data is then based on this. However if they then view another persons profile, the information will not be correct because it will alter to show whatever result was pulled from $ session.

How would I create properly functioning profile pages. A good example of what I am trying to achieve would be YouTube. Whenever a user adds a comment, their username is attached, this then acts as a link to their profile.

I don't have any code for this. I wouldn't know where to start.

Upvotes: 0

Views: 661

Answers (3)

Satish Sharma
Satish Sharma

Reputation: 9635

you are using session of username of user which is logged in.

so user who is logged in can view his own profile with session username.

if user want to view profile of another user then there you have two way to perform it.

  1. Create another page to view any user profile. pass username as query string and find user information which you want to display.

or

2-Use same page of user profile for your own and other. and pass the username on this page whose information you want to display.

you have to apply a condition there that is -- if there is set a username pass through post or get method retrieve the information of the passed user. or if not set that retrieve the information of the user which is in session (own information)

Upvotes: 0

J2D8T
J2D8T

Reputation: 825

Because there is no code for me to try and help you out I will give you a few pointers.

  1. First of all don't use the usernames of the users to identify and link them to their profile 2 or more people could have the same username then you are screwed, rather use their id's to uniquely identify them.

  2. Keep the users data that is currently logged in, in the session variables because you don't want to lose this when he navigates away from the browse user profiles page.

  3. If you use the users id's to identify them you can send their id through the url without to much of a security issue. So where you display all the users to view you can create a url that looks something like this href="user_profile.php?user_id=<?php echo $user_id; ?>". Then on the page where you want to view the user profile that has been selected you can use $_GET['user_id']. You can then use the id to get all the details for that specific user by querying the databse for a user with this user_id.

Upvotes: 1

himanshu bhardiya
himanshu bhardiya

Reputation: 81

destroy the session while user logout. so you can got proper data

Upvotes: 0

Related Questions