我正在尝试创建一个简单的会员登录网站,并且我正在跟随在线教程。但是,这里使用了一个已弃用的函数。代码如下:
<?php
session_start();
session_destroy();
if(isset($_COOKIE['id']))
{
//remove cookie
setcookie("$id_cookie", '', time() - 50000);
setcookie("$pass_cookie", '', time() - 50000);
}
if(!session_is_registered('username'))
{
header("Location: index.php");
}
else
{
exit('Sorry we could not log you out');
}
?>
我也试过!isset($_SESSION['username'])
,但每次我试图注销,我只是收到"对不起,我们不能注销你"的文本。
下面是我的login.php文件代码的一部分,我在这里设置会话:
//member does exist, start sessions
$_SESSION['password'] = $password;
while($row = mysql_fetch_array($query))
{
$username = $row['username'];
$id = $row['id'];
}
$_SESSION['username'] = $username;
$_SESSION['id'] = $id;
任何帮助将是伟大的!
不要使用
session_is_registered
使用if (isset($_SESSION['SESSION_VARIABLE_NAME']))
你可以在"session_destroy(); "
session_destroy()删除会话文件,释放会话id,但在内存中保留$_SESSION变量
将此用于isset
if(!isset($_SESSION['username']))
试试这个
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
if(!isset($_SESSION['username']))
{
header("Location: index.php");
}
检查会话是否存储在哪里
在注销脚本中试试这段代码
<?php
session_start();
if(isset($_SESSION['id']))
{
unset($_SESSION['username']);
unset($_SESSION['id']);
}
if(!isset($_SESSION['username']))
{
header("Location: index.php");
}
else
{
exit('Sorry we could not log you out');
}
?>