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
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>'; 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.