droidus Posted August 28, 2011 Share Posted August 28, 2011 i am trying to redirect a user to a certain page, if the credentials are not right. if there is no session user, they are kicked out. if it is set, but to the guest account, they go to the login page with a special error message. here is my code for it: if (!isset($_SESSION['user'])) { header('Location: portal.php?logintocontinue'); exit; } elseif($_SESSION['user'] == "guest") { header('Location: portal.php?invalidLogin'); exit; } else { } after attempting to run the page, with session user = guest, i get this error message: The page isn't redirecting properly. does it have to do with headers already being sent? Quote Link to comment https://forums.phpfreaks.com/topic/245885-redirecting-user/ Share on other sites More sharing options...
Pikachu2000 Posted August 28, 2011 Share Posted August 28, 2011 Can't tell from that amount of code. Quote Link to comment https://forums.phpfreaks.com/topic/245885-redirecting-user/#findComment-1262846 Share on other sites More sharing options...
droidus Posted August 28, 2011 Author Share Posted August 28, 2011 i am not sure what else to add... before, i just had the if (!isset($_SESSION['user'])) { header('Location: portal.php?logintocontinue'); exit; } and it worked. when i added the elseif statement/else, it stopped working. Quote Link to comment https://forums.phpfreaks.com/topic/245885-redirecting-user/#findComment-1262848 Share on other sites More sharing options...
Pikachu2000 Posted August 28, 2011 Share Posted August 28, 2011 In that case, it's probably working as it's written and going into the empty else{} clause. Did you echo $_SESSION['user'] to verify it's value? Quote Link to comment https://forums.phpfreaks.com/topic/245885-redirecting-user/#findComment-1262850 Share on other sites More sharing options...
phpWilliam Posted August 28, 2011 Share Posted August 28, 2011 what is the datatype of $_SESSION['user'] Your code appears to handle it as a string. Is it perhaps an object or an array, thus $_SESSION['user']['type'] should be compared? as Pikachu2000 said, little more info would be handy thanks, Quote Link to comment https://forums.phpfreaks.com/topic/245885-redirecting-user/#findComment-1262854 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.