doubledee Posted August 23, 2011 Share Posted August 23, 2011 Why is my SESSION not getting set in the code below?! <?php // Initialize a session. session_start(); // Initialize Logged-In Status. $_SESSION['loggedIn'] = FALSE; // Display Logged-In Status. echo '<p>$_SESSION[\'loggedIn\'] = ' . $_SESSION['loggedIn'] . '</p>'; exit(); When I run this I get... $_SESSION['loggedIn'] = Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/ Share on other sites More sharing options...
Pikachu2000 Posted August 23, 2011 Share Posted August 23, 2011 var_dump($_SESSION['loggedIn']); Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260797 Share on other sites More sharing options...
doubledee Posted August 23, 2011 Author Share Posted August 23, 2011 var_dump($_SESSION['loggedIn']); I actually tried setting it to "TRUE" and "FALSE" and the branching that depends on $_SESSION['loggedIn'] seems to be working, but why isn't the value being echoed?! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260798 Share on other sites More sharing options...
Pikachu2000 Posted August 23, 2011 Share Posted August 23, 2011 Because it isn't a string, it's a boolean. A true value should echo 1, a false will echo nothing. if( $_SESSION['loggedIn'] === TRUE ) { echo 'True'; } if( $_SESSION['loggedIn'] === FALSE ) { echo 'False'; } Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260799 Share on other sites More sharing options...
doubledee Posted August 23, 2011 Author Share Posted August 23, 2011 Because it isn't a string, it's a boolean. A true value should echo 1, a false will echo nothing. if( $_SESSION['loggedIn'] === TRUE ) { echo 'True'; } if( $_SESSION['loggedIn'] === FALSE ) { echo 'False'; } Why doesn't FALSE echo as zero (0)??? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260800 Share on other sites More sharing options...
darkfreaks Posted August 23, 2011 Share Posted August 23, 2011 <?php // Initialize a session. session_start(); function login() { $_SESSION['loggedIn'] = TRUE; } // Display Logged-In Status. echo login(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260816 Share on other sites More sharing options...
doubledee Posted August 23, 2011 Author Share Posted August 23, 2011 <?php // Initialize a session. session_start(); function login() { $_SESSION['loggedIn'] = TRUE; } // Display Logged-In Status. echo login(); ?> I don't get it? Someone said earlier that TRUE should echo as "1"? Any other language I've ever programmed in would display a BOOLEAN? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260820 Share on other sites More sharing options...
darkfreaks Posted August 23, 2011 Share Posted August 23, 2011 yes so if the session is set as TRUE or 1 the user should be logged in. Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260822 Share on other sites More sharing options...
doubledee Posted August 23, 2011 Author Share Posted August 23, 2011 yes so if the session is set as TRUE or 1 the user should be logged in. Are you baiting me and trying to start a fight?? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/245478-session-not-being-set/#findComment-1260829 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.