Can someone please tell me why I'm able to echo inside of this block when the session clearly has a value?
$_SESSION['test']['testing'] = 'hgkjhg';
echo $_SESSION['test']['testing']; // Produces hgkjhg (Clearly not empty)
if(empty($_SESSION['test']['testing'])){
echo 'Hello'; // This echoes and to me, shouldn't
}
The real answer is about session_start. Unlike session_register, assigning directly to $_SESSION does not automatically call session_start.
Directly from PHP manual for session_register()
If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With