wepnop Posted May 15, 2011 Share Posted May 15, 2011 Hi. I have to check if a session is started or not, and then, check for the rank of the user. For that i use two functions like is_administrator,etc. Well, but this isnt working. I cant get any clear way to know if a session have been already started or not. function is_administrator() { session_start(); if (isset($_SESSION['usr']) and empty($_SESSION['usr'])) { $l = conect(); $user = $_SESSION['usr']; $cons = "SELECT * FROM `users` WHERE usr='" . $user . '\';'; $res = mysql_query ($cons,$l); $ob = mysql_fetch_array($res); if ($ob['tipo'] == 'A') { return true; } } return false; } What i want to do is to check if a sesion exist, if not, return false. If the sesion exist, check for the user rank and return true/false. Quote Link to comment https://forums.phpfreaks.com/topic/236493-strange-session-problem/ Share on other sites More sharing options...
MidOhioIT Posted May 15, 2011 Share Posted May 15, 2011 try this instead: if ( ($_SESSION["usr"]) ) that should be good enough to test if it is set or not... Quote Link to comment https://forums.phpfreaks.com/topic/236493-strange-session-problem/#findComment-1215826 Share on other sites More sharing options...
matthew9090 Posted May 16, 2011 Share Posted May 16, 2011 don't put the session start in the function put it at the very top of the page the it using the function Quote Link to comment https://forums.phpfreaks.com/topic/236493-strange-session-problem/#findComment-1215907 Share on other sites More sharing options...
Sanjib Sinha Posted May 16, 2011 Share Posted May 16, 2011 Before sending any header text to the page the session should start. So it is always wise and good practice to keep it in a 'require.php' and put it on the top. Please note when working with sessions that a record of a session is not created until a variable has been registered using the session_register() function or by adding a new key to the $_SESSION superglobal array. This holds true regardless of if a session has been started using the session_start() function. Quote Link to comment https://forums.phpfreaks.com/topic/236493-strange-session-problem/#findComment-1215915 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.