PHP---if(!session_)已注册不推荐?
此if语句已被弃用PHP---if(!session_)已注册不推荐?,php,Php,此if语句已被弃用 if(!session_is_registered('firstname')){ header("location: index.php"); // << makes the script send them to any page we set } else { print "<h2>Could not log you out, sorry the system encountered an error.</h2>"; exit();
if(!session_is_registered('firstname')){
header("location: index.php"); // << makes the script send them to any page we set
} else {
print "<h2>Could not log you out, sorry the system encountered an error.</h2>";
exit();
}
如果(!session_已注册('firstname')){
页眉(“location:index.php”);//页面上是否有session_start()
根据你的第一个片段,我认为你在逻辑上失败了
尝试:
if(!isset($\u会话['firstname'])){
header(“location:index.php”);//若要使用基于cookie的会话,必须在将任何内容输出到浏览器之前调用session_start()。如果$\u session['firstname']
可能为null但已设置,请尝试数组_key_exists('firstname',$\u session)
此外,在第一个示例中,如果变量不存在,则重定向;在第二个示例中,如果变量存在,则重定向。这是您的预期操作吗?
if ( isset( $_SESSION['firstname'] ) ){
header("location: index.php"); // << makes the script send them to any page we set
} else {
print "<h2>Could not log you out, sorry the system encountered an error.</h2>";
exit();
if ( !isset($_SESSION['firstname']) ){
header("location: index.php"); // << makes the script send them to any page we set
} else {
exit('<h2>Could not log you out, sorry the system encountered an error.</h2>');
}