Jump to content

Simple memberlist problem


MishieMoo

Recommended Posts

Okay so I'm making a memberlist for my site.  I've been able to get it to display the members, and have a link to the member's profile that displays some info.  The problem is that when you click on a member, it logs you in as that member for some reason.  I think it has something to do with the id, as that's how the memberlist is displayed.  No matter what user it is, if you click their name on the list you can update their settings. I've tried playing around with it and I have no idea what's up.  My site uses sessions to store login info, if that info helps at all.

 

Here's the code:

<?php session_start();//starts the session

require ("db_config.php");//Makes sure we are connected to the database
$pagename = 'Memberlist';
include('header.php');
if ($id <="0"){ //if the id is equal to 0

print "<h2>Members registered on Xuthonia!</h2>";//Page header

$find = mysql_query("SELECT * FROM users");//Querries the database for all users
while ($row = mysql_fetch_array($find)){ //Fetches the array
	extract($row); 
	echo '<a href="members.php?id='.$id.'">'.$name.'</a><br />';
	//A link to members.php and tells the page the member it wants is the member you clicked on
}

}

else //If not

{

$uid = mysql_query("SELECT * FROM users WHERE id = '$id'"); //Searches the database for the user with the id specified in the url
while ($u = mysql_fetch_array($uid)){ //Fetches the array
	extract($u);
	print "<h4>$u[username]'s profile</h4>"; //Shows the username then 's profile in a heading

	print "<strong>Avatar:</strong>"; //Avatar in bold

	print "$u[av]<br />"; //Shows the avatar in the row

	print "<strong>Gender:</strong>"; //Gender in bold

	print "$u[gender]<br />"; //Shows the gender in the row

	print "<strong>Email Address:</strong>"; //Email Address in bold

	print "$u[email]<br />"; //Shows the email address in the row

	$back = $id - 1; //The id in the url minus 1

	$forward = $id + 1; //The id in the url plus 1

	print '<a href="/members.php?member=$back">Last:</a>'; //A link to the previous profile

	print '<a href="/members.php?member=$forward">Next</a>';//A link to the next profile


	}

}


include('footer.php');
?>

Link to comment
Share on other sites

Well the user's id is registered when they login as $_SESSION['userid'].

 

I forgot to put in the $id = $_GET['id']; at the beginning...or forgot to put it back in.  But it's there now xD

 

And I put in a feature that displays the username, id and rank of who you're logged in as, and for some reason everything but the id changes.  My id is #1, and then the other two members are #2 and #3.  When I click their profiles, I become logged in as either of them, but my id stays the same.

 

It seems to be affecting my sessions, even though there's no session declaration on the page (yet...I haven't added the if logged in stuff yet).

Link to comment
Share on other sites

The code is exactly the same with the inclusion of the $id thing at the top.  That's the only thing I've changed.  The check is in the header.php file, which is included in the page.

 

The check

echo 'Logged in as '.$_SESSION['username'].' (#'.$_SESSION['userid'].')<br />';
echo 'Userlevel: ';
if($_SESSION['rank'] == 0) {print 'Member';}
if($_SESSION['rank'] == 1) {print 'Moderator';}
if($_SESSION['rank'] == 2) {print 'Admin';}
if($_SESSION['rank'] == 3) {print 'Mega Admin';}

 

And the very very similar main code

<?php session_start();//starts the session

require ("db_config.php");//Makes sure we are connected to the database
$pagename = 'Memberlist';
$id=$_GET['id'];
include('header.php');
if ($id <= 0){ //if the id is equal to 0

print "<h2>Members registered on Xuthonia!</h2>";//Page header

$find = mysql_query("SELECT * FROM users");//Querries the database for all users
while ($row = mysql_fetch_array($find)){ //Fetches the array
	extract($row); 
	echo '<a href="members.php?id='.$id.'">'.$name.'</a><br />';
	//A link to members.php and tells the page the member it wants is the member you clicked on
}

}

else //If not

{

$uid = mysql_query("SELECT * FROM users WHERE id = '$id'"); //Searches the database for the user with the id specified in the url
while ($u = mysql_fetch_array($uid)){ //Fetches the array
	extract($u);
	print "<h4>$u[username]'s profile</h4>"; //Shows the username then 's profile in a heading

	print "<strong>Avatar:</strong>"; //Avatar in bold

	print "$u[av]<br />"; //Shows the avatar in the row

	print "<strong>Gender:</strong>"; //Gender in bold

	print "$u[gender]<br />"; //Shows the gender in the row

	print "<strong>Email Address:</strong>"; //Email Address in bold

	print "$u[email]<br />"; //Shows the email address in the row

	$back = $id - 1; //The id in the url minus 1

	$forward = $id + 1; //The id in the url plus 1

	print '<a href="/members.php?member=$back">Last:</a>'; //A link to the previous profile

	print '<a href="/members.php?member=$forward">Next</a>';//A link to the next profile


	}

}


include('footer.php');
?>

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.