我有以下PHP代码:
if(!isset($_SESSION)) {
session_destroy();
header('Location: register.php'); //redirect to the orginal form
} else {
$businessOwnerID = $_SESSION['business_owner_id']; //The Business owner ID
$mobileValidation = $_SESSION['mobile_validation'];
}
我不明白为什么它不重定向到register.php
我尝试通过执行session_destroy()来销毁所有会话;但是它也不工作
因为你显然不想检查是否有一个会话(通常会有)但是如果设置了特定的会话属性,你应该这样做:
if(!isset($_SESSION['business_owner_id'], $_SESSION['mobile_validation']))
{
session_destroy();
header('Location: register.php'); //redirect to the original form
}
...
$_SESSION
超全局变量总是在调用session_start()
后设置
相反,您应该检查是否设置了特定值:
if(!isset($_SESSION['business_owner_id'])) {
session_destroy();
header('Location: register.php'); //redirect to the orginal form
} else {
$businessOwnerID = $_SESSION['business_owner_id']; //The Business owner ID
$mobileValidation = $_SESSION['mobile_validation'];
}