MishieMoo Posted December 1, 2007 Share Posted December 1, 2007 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'); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 First thing if ($id <="0") $id is not normally a string, so don't compare it to one if ($id <= 0) Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 2nd thing, where are you getting the initial $id from? I don't see anyting setting it. Quote Link to comment Share on other sites More sharing options...
MishieMoo Posted December 1, 2007 Author Share Posted December 1, 2007 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). Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 Post your updated code. Quote Link to comment Share on other sites More sharing options...
MishieMoo Posted December 1, 2007 Author Share Posted December 1, 2007 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'); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 You still have "0" instead of 0 Quote Link to comment Share on other sites More sharing options...
MishieMoo Posted December 1, 2007 Author Share Posted December 1, 2007 That's because I'm now using my bf's computer and I don't have the code in front of me to copy n paste. I modified it to what I have. I forgot about that when I copied it. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 Your URLs look wrong You are setting the URL to <a href="/members.php?member=$back">Last:</a>' But you are $_GETting "id". So either $_GET['member'] or change the url to members.php?id= Quote Link to comment Share on other sites More sharing options...
MishieMoo Posted December 1, 2007 Author Share Posted December 1, 2007 That doesn't do anything except make the back and forward links work (kind of. I had to change the print to an echo in order to make it work). It's still switching who I'm logged in as. And it does so whenever I visit whichever page. Quote Link to comment Share on other sites More sharing options...
MishieMoo Posted December 1, 2007 Author Share Posted December 1, 2007 Okay...now it's just setting me to the settings for id #3 whenever I go to the memberlist page....WHAT? Can someone please give me some sort of useful feedback on why this is affecting my session? Quote Link to comment Share on other sites More sharing options...
MishieMoo Posted December 1, 2007 Author Share Posted December 1, 2007 ...? Anyone =( I can't add the memberlist to the site until this is fixed. I can't have people using the admin areas... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.