Reputation: 21
I have a site that allows users to sign up and create profiles. I have a basic user profile link in the header that allows users to link back their profile page when viewing other pages. The script works fine. The problem is that now I have separate user profile pages for the two different types of users. User1 links to profile.php and User2 links to profile2.php. The issue is I'm not sure how to make the script look at the user type and display either profile.php or profile2.php based off of the status of the user that's logged in.
Here is the code I have:
<?php
if(isset($_SESSION['valid'])&&$_SESSION['valid']==true){
// INSERT USER LOGGED IN MESSAGE BELOW AS HTML
?>
<h3><a href='profile.php'><?php echo $_SESSION['userName']; ?></a></h3>
<a href="login.php?action=logout">Logout</a>
<?php
// END OF IF LOGGED IN STMT
}
?>
I basically want the script to read if User1 is logged in then link to profile.php but if User2 is logged in link to profile2.php. How can I accomplish this with the script I have?
Upvotes: 0
Views: 2396
Reputation: 20475
You are going about this all wrong, you should just make the profile.php
look at the user id, or user reference (username, etc).
Your logic would be like so:
profile.php?uid=USERNAME
uid
valueprofile.php example:
<?php
if(isset($_GET['uid'])){
$username = sanitize($_GET['uid']); // sanitize is not a function, just implying that data is insecure and requires to be santized through whatever method you choose.
$details = get_user_details($username); // this will check your database/file etc for details on user.
} else {
// user is not requested $_GET['uid'], nothing to show
echo "User not found!";
exit();
}
// output details in any format you desire for queried user
?>
Upvotes: 0