AbydosGater Posted November 27, 2006 Share Posted November 27, 2006 Hi, For my members area..I have a header file that contains...[code]<?phpif (!$_SESSION['user']){ header('Location: http://www.shadowfleet.info');exit;};if ($_SESSION['user']['banned'] == "1"){unset($_SESSION['user']);header('Location: http://yourbanned.com');exit;}?>[/code]Thats just the important bit...And it works great fine works perfeck on all my proteced pages..But i made a members list today with...[code]<?php echo" <table width='100%' border='0'> <tr> <td><div align='center'><font color='#FFFFFF'><strong>Member Id</strong></font></div></td> <td><div align='center'><font color='#FFFFFF'><strong>Rank</strong></font></div></td> <td><div align='center'><font color='#FFFFFF'><strong>Username</strong></font></div></td> <td><div align='center'><font color='#FFFFFF'><strong>Profile</strong></font></div></td> </tr>";$query = "SELECT * FROM sf_users ORDER BY member_id ASC";$result = mysql_query($query); while($user = mysql_fetch_array($result)) {$member_id = $user['member_id'];$rank = $user['rank'];$username = $user['username'];echo " <tr> <td><div align='center'><font color='#FFFFFF'>$member_id</font></div></td> <td><div align='center'><font color='#FFFFFF'>$rank</font></div></td> <td><div align='center'><font color='#FFFFFF'>$username</font></div></td> <td><div align='center'><em><font color='#FFFFFF'>Comming Soon</font></em></div></td> </tr>";};echo "</table>";?>[/code]And it works.. But if your on that page, and you go back to another protected page, the sessions gone.. and it redirects you to the homepage...This is being done on a non banned account, and im logged inworking fine on the rest of the files, but this page is unsetting the session...Has anyone any ideas?Please help me! Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2006 Share Posted November 27, 2006 I dont see a call to session_start() anywhere. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 27, 2006 Share Posted November 27, 2006 Did you call session_start() on every page that needs it? Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 27, 2006 Author Share Posted November 27, 2006 Yeah its in the header file with other stuff... The script works fine on all other pages, just made this one today, and it works at first but if you refresh its killed the session Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 28, 2006 Author Share Posted November 28, 2006 Ive been reading through the code... Its grand. it works fine with every other page... but this one.. why the hell is it unsetting the session?Its running both of the If statments when it shouldnt.. the users not banned... and the session['user'] IS set...It shouldnt be unsetting the session.. and it shouldnt be redirecting to the the index..Anyone understand whats happening? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 28, 2006 Share Posted November 28, 2006 Near the top of the page in question:[code]echo '<pre style="text-align: left;">' . print_r($_SESSION, true) . '</pre>';[/code] Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 28, 2006 Author Share Posted November 28, 2006 Ok i have put that in.. Just after i require the header file... and yes.. it echoed my session information as an array...This is all after the part for unsetting the session (Even though this part should not be run) But i dont think it is.. If it was unsetting the session in the header file... why would it display the info after?And still its being unset because after that i refreshed the page and it went back to the index :(:(Somethings very wrong.. because then my browser crashed and only that window closed:P i dont know whats happening Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 28, 2006 Author Share Posted November 28, 2006 OK... Ive been here over 2 hours sitting only got up once trying to get this fixed..And i have finally realised that the problem exists in my code that is calling the members list.. as when i commented it out... everything worked fine no problemsThe code is as follows...[code]<?php echo" <table width='100%' border='0'> <tr> <td><div align='center'><font color='#FFFFFF'><strong>Rank</strong></font></div></td> <td><div align='center'><font color='#FFFFFF'><strong>Username</strong></font></div></td> <td><div align='center'><font color='#FFFFFF'><strong>Profile</strong></font></div></td> </tr>";$query = "SELECT * FROM sf_users ORDER BY member_id ASC";$result = mysql_query($query); while($user = mysql_fetch_array($result)) {$member_id = $user['member_id'];$rank = $user['rank'];$username = $user['username'];echo " <tr> <td><div align='center'><font color='#FFFFFF'>$rank</font></div></td> <td><div align='center'><font color='#FFFFFF'>$username</font></div></td> <td><div align='center'><em><font color='#FFFFFF'>Coming Soon</font></em></div></td> </tr>";};echo "</table>";?>[/code]Anyone see why that code would kill a session?EDIT:: Ok ive just realised that im using $user['']; to store the information.... DUHHHHH thats what im using for the session $_SESSION['user']; is the user info.. ive had problems like this in the past.. is it cause the vars are the same?? 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.