damdempsel Posted December 20, 2009 Share Posted December 20, 2009 I have a log in script where a session is set with the persons username and there is also another session set if they are an admin. The admin session seems to be having a bit of trouble. On my admin page, if there is no admin session it will log their IP and send them to the index page. There is also a list of links that only admins can see. When I sign in with an admin account, I am able to see the links but I can't go to the admin pages. I use pretty much the same codes to display the links and to allow access to the pages. The code I use for setting the admin session is: $_SESSION['admin'] = $username; The code I use for the links is: if ($_SESSION['admin']) {} ^-- I removed bits of code from this. This is just the main part of it. The code for the admin page is: if (!$_SESSION['admin']) { header("location: index.html");} ^-- This is just the main part of the code. Setting the session works fine, and displaying the links is fine. The only problem is the admin page. Does anyone see something wrong with that part of the code? Link to comment https://forums.phpfreaks.com/topic/185804-sessions/ Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Well, if you are unable to view the admin pages using if (!$_SESSION['admin']) { header("location: index.html");} I would suggest try var_dumping($_SESSION['admin']) and tell us what the value is. My first guess is that it is getting redefined somewhere else as "" or unset. Link to comment https://forums.phpfreaks.com/topic/185804-sessions/#findComment-981092 Share on other sites More sharing options...
nafetski Posted December 20, 2009 Share Posted December 20, 2009 Oh also goes without saying...but make sure that at the top of the page <?php session_start(); Is there. Otherwise PHP won't have access to the session array, and in that case it will always return false. Link to comment https://forums.phpfreaks.com/topic/185804-sessions/#findComment-981093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.