derekbelcher Posted April 23, 2009 Share Posted April 23, 2009 Hello. I am having trouble getting my session to work in php. I have a login page that sends the username and password to a "checklogin" page. Here I have code that sets the session if the right credentials are submitted: if($count==1){ // Register $myusername, $mypassword and redirect $_SESSION['myusername']=$myusername; $_SESSION['mypassword']=$mypassword; // Redirect to appropriate admin page while($row=mysql_fetch_assoc($result)){ $adminpage=$row['admin_redirect']; } header("location:$adminpage"); } else { header("location:adminLoginError.php"); } On the successful login page I have this code: <?php if(!isset($_SESSION['myusername'])) { header("location:adminLogin.php"); } ?> For some reason I am not getting to the success page. When you enter the username and password you just get a new login page. I am assuming that it is not recognizing a registered Session. If I remove the (!) from before isset, then it works fine, but I know that it is not checking the username and password. Help please! Link to comment https://forums.phpfreaks.com/topic/155404-solved-having-trouble-setting-session/ Share on other sites More sharing options...
Zhadus Posted April 23, 2009 Share Posted April 23, 2009 Did you remember to put use session_start() at the beginning of both pages? Link to comment https://forums.phpfreaks.com/topic/155404-solved-having-trouble-setting-session/#findComment-817738 Share on other sites More sharing options...
derekbelcher Posted April 23, 2009 Author Share Posted April 23, 2009 What an idiot! I had it on checklogin, but not on the success page. Too funny! thanks, Link to comment https://forums.phpfreaks.com/topic/155404-solved-having-trouble-setting-session/#findComment-817742 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.