1

I'm trying to create a simple member login site, and I was following along with a tutorial online. However, a deprecated function is used. Here is the code.

<?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');
}

?>

I also tried !isset($_SESSION['username']), but every time I try to log out, I just receive the 'Sorry we could not log you out' text.

Here is the part of my login.php file code where I set the sessions:

//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;

Any help would be great!

4

5 回答 5

2

不要使用

session_is_registered 

利用

if (isset($_SESSION['SESSION_VARIABLE_NAME']))
于 2013-04-24T05:27:55.170 回答
1

您可以添加“session_unset();” 在“session_destroy();”之前

session_destroy() 删除会话文件并释放会话 ID,但将 $_SESSION 变量保留在内存中。

于 2013-04-24T05:51:34.730 回答
0

在您的注销脚本中尝试此代码

<?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');
}

?>
于 2013-04-24T10:26:13.487 回答
0

用这个isset

if(!isset($_SESSION['username']))
于 2013-04-24T05:28:26.563 回答
0

Try this

echo "<pre>";
   print_r($_SESSION);
echo "</pre>";


if(!isset($_SESSION['username']))
{
    header("Location: index.php");
}

Check where the the SESSSION is stored or not.

于 2013-04-24T05:31:39.747 回答