Jump to content

$_SESSION values, linking?? Help


unsider

Recommended Posts

Ok.

 

So let's assume I have three users.

 

Tim

Bob

Chad

 

They each are allowed to post comments once they have registered. Well once they post, there $_SESSION['username'] is displayed, and with it a link to their 'profile'. That's where the error is.

 

EDIT: no error in code, just the manner in which it functions, continue reading.

 

<?php

$username = $_SESSION['username'];

while($row = mysql_fetch_array($result))
{


echo '<tr class="tr' . $tr . '"><td>' 
. '<img src="http://example.com/main/images/post.gif">' 
. "<a href='userinfo.php?user=$username'>" . $row["username"] 
. '</a>' . '<br>' . ' posted on: ' . '<br><br>' 
. ' ' . $row["commenttext"] 
. '</td></tr>'; 

?>

 

If no user is not logged in, it displays to everyone:

 

http://example.com/main/userinfo.php?user=Guest

 

If the user is logged in as Tim, but clicks the link to Bob's profile it displays his (Tim's) profile. And vise versa.

 

I am trying to establish unique properties between each user, so that no matter who you are logged in as, you will be able to view that person's profile.

 

I unfortunately do not know how to explain this, but think of this website, you can be logged on and click on someone else's profile and view their info.

 

Ask questions if I have not clarified something correctly, otherwise, I really need help with this problem.

 

 

Link to comment
https://forums.phpfreaks.com/topic/96261-_session-values-linking-help/
Share on other sites

What you want to do will not work. A Session is for one user.

 

Since you are getting the username out of the database anyway why not use that?

<?php
/*$username = $_SESSION['username'];*/
while($row = mysql_fetch_array($result))
{
$username=$row['username']	

echo '<tr class="tr' . $tr . '"><td>' 
. '<img src="http://example.com/main/images/post.gif">' 
. "<a href='userinfo.php?user=$username'>" . $username 
. '</a>' . '<br>' . ' posted on: ' . '<br><br>' 
. ' ' . $row["commenttext"] 
. '</td></tr>'; 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.