Trium918 Posted May 30, 2007 Share Posted May 30, 2007 Is this legitimate? <?php session_start(); if(!$_SESSION['id'] && !$_SESSION['valid_user']){ header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/ Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 I would go about it this way: <?php session_start(); if((!isset($_SESSION['id']) || !$_SESSION['id']) && (!isset($_SESSION['valid_user']) || !$_SESSION['valid_user'])){ header("Location: login.php"); } ?> To avoid notice's etc. Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/#findComment-265080 Share on other sites More sharing options...
The Little Guy Posted May 30, 2007 Share Posted May 30, 2007 Yes, if $_SESSION['id'] and $_SESSION['valid_user'] are both boolean values (TRUE or FALSE) Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/#findComment-265081 Share on other sites More sharing options...
Trium918 Posted May 30, 2007 Author Share Posted May 30, 2007 Yes, if $_SESSION['id'] and $_SESSION['valid_user'] are both boolean values (TRUE or FALSE) What exactly do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/#findComment-265123 Share on other sites More sharing options...
Barand Posted May 30, 2007 Share Posted May 30, 2007 Even if they're booleans it's better to check if they exist, as in frost's post. Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/#findComment-265124 Share on other sites More sharing options...
The Little Guy Posted May 30, 2007 Share Posted May 30, 2007 in order for that code to work, it is looking for the value of these two variable: $_SESSION['id'] $_SESSION['valid_user'] to either be TRUE or FALSE; ----- $_SESSION['id'] = FALSE; or $_SESSION['id'] = TRUE; ----- $_SESSION['valid_user'] = FALSE; or $_SESSION['valid_user'] = TRUE; ----- if the variable isn't set, it will automatically be set to FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/#findComment-265126 Share on other sites More sharing options...
Trium918 Posted May 30, 2007 Author Share Posted May 30, 2007 in order for that code to work, it is looking for the value of these two variable: $_SESSION['id'] $_SESSION['valid_user'] to either be TRUE or FALSE; ----- $_SESSION['id'] = FALSE; or $_SESSION['id'] = TRUE; ----- $_SESSION['valid_user'] = FALSE; or $_SESSION['valid_user'] = TRUE; ----- if the variable isn't set, it will automatically be set to FALSE. Both scripts are redirecting back to login if the user isn't logged in. That will make it true if the user logs in, and false if the user isn't logged in, correct? <?php session_start(); if(!$_SESSION['id'] && !$_SESSION['valid_user']){ header("Location: login.php"); } ?> <?php session_start(); if((!isset($_SESSION['id']) || !$_SESSION['id']) && (!isset($_SESSION['valid_user']) || !$_SESSION['valid_user'])){ header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53629-solved-question/#findComment-265131 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.