Help with PHP login system

Hi, i have a login system all working fine, but i want for other people to be able to view another persons provided information, which they can by selecting that persons username. however i do not want them to see all of the persons provided information.

For example when the account owner login they should see all the data they provided to us upon registering. But the code im using also allows another account holder to see all this data too rather then just certain bits of it.


/* Logged in user viewing own account */
if(strcmp($session->username,$req_user) == 0){
   echo "<h1>My account!</h1>";
}
/* Visitor not viewing own account */
else{
   echo "<h1>User account information!</h1>";
}
 
(USERS ACCOUNT INFORMATION IS DISPLAYED HERE.) i have tried putting this information before
 
/* Visitor not viewing own account */
else{
   echo "<h1>User account information!</h1>";
}
 
Hoping all i would then see when selecting a users account other than my own is 'user account information' and build on that. But instead i get a blank white page.
 
So is there a way i can have the account owner see all thier data and have other accounts only able to see certain bits of that data or none at all.

Open in new window

LVL 1
james130cAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
BrianGEFF719Connect With a Mentor Commented:
You can do it as two queries, for example, if the user is viewing their own account do something like:

 SELECT * from `users` where `User.username` = '$session->username' LIMIT 1;

And when it's someone else viewing the account you can do a different query:

  SELECT `User.username`, `User.firstname`, `User.lastname` FROM `users` where `User.username`=$req_user LIMIT 1;
0
 
james130cAuthor Commented:
To put it into plain english something like
/* Visitor not viewing own account */
else{
   echo "<h1>You do not have permission to access this account information!</h1>";
}
 
(and the account information is not displayed) At the moment the above is fine but although it says 'you do not have permission' , they do seem to... view someone elses account details.

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
could not understand what are explaining?
0
All Courses

From novice to tech pro — start learning today.