session_start();
if (!session_is_registered(user)) {
header("Location: login.php");
die();
}
What is the proper way to do this since session_is_registered()
is deprecated?
if (empty($_SESSION['user'])){
// session user does not exist
}
use if ( isset( $_SESSION['user'] ) ){}
isset() will not do what you want all of the time. It will fail if 'user' is falsy (0, false, null, empty string). array_key_exists() will match the truth table of session_is_registered, despite what php.net says:
if ( !array_key_exists( 'user', $_SESSION ) ){
/* 'user' is in the session */
}
//in other words...
if ( array_key_exists( 'user', $_SESSION ) === session_is_registered( 'user' ) ) {
/* This is always executed */
}
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