2011-03-12 74 views
13
session_start(); 
if (!session_is_registered(user)) { 
    header("Location: login.php"); 
    die(); 
} 

由于session_is_registered()已过时,因此采取了何种方法来解决此问题?弃用session_is_registered的替代方案

+1

这将是有益的,如果“他们”会把通知PHP手册为“推荐”的替换功能时的东西已弃用。 – salonMonsters 2011-07-05 19:03:07

回答

22

使用if (isset($_SESSION['user'])){}

+0

我会这样做,并把一个其他头(“位置:index.php”);死();或者死();不需要? – Kyle 2011-03-13 00:01:01

+1

退出;应该在使用header()重定向后始终使用。死亡可能也会起作用。 – Galen 2011-03-13 00:02:56

0

在login.php中页上,如果您的用户名和密码是匹配的话,那就由

session_register("y"); //where y register the user 
header("location:user.php&name=$y"); 

注册用户在user.php的页面

session_start(); 
if(!isset($_SESSION['y'])) // if the user is not the same user that logged in then 
{       // it redirects to the login page 
    header("location:login.php"); 
} 
0
if (empty($_SESSION['user'])){ 
    // session user does not exist 
} 
1

isset()不会做你想要的所有时间。如果'user'是虚假的(0,false,null,空字符串),它将失败。 array_key_exists()会的session_is_registered真值表,尽管相匹配什么php.net说:

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 */ 
}