有问题的cookie

时间:2012-02-09 04:33:28

标签: php cookies

使用以下代码检查Cookie

        if (!isset($_COOKIE['auth'])) {
            header('Location:' . wsurl);
        }

即使浏览器显示该网站有cookie,我的php代码也会重定向到网站网址

enter image description here

什么可能导致这个问题?

整个代码看起来像那样。

public function protect() {
    if (!isset($_SESSION)) {
        session_start();
    }
    $data = array();

    if (isset($_SESSION['auth'])) {
        $stmt = $this->db->prepare("SELECT l.browser, l.ip, u.ban from log AS l, users AS u WHERE l.token =? AND u.id=l.user_id LIMIT 1") or die($this->db->error);
        $stmt->bind_param("s", $_SESSION['auth']) or die($stmt->error);
        $stmt->execute() or die($stmt->error);
        $stmt->store_result();
        if ($stmt->num_rows == 0) {
            $this->signout();
        }
        $stmt->bind_result($data['browser'], $data['ip'], $data['ban']);
        $stmt->fetch() or die($stmt->error);
        $stmt->close() or die($stmt->error);
        $result = $this->validation->check("protection", $data);
        if ($result != true) {
            $result = (is_numeric($result)) ? $result : true;
            $this->signout($result);
        }
    } else {
        if (!isset($_COOKIE['auth'])) {
            header('Location:' . wsurl);
        }
        $stmt = $this->db->prepare("SELECT l.browser, l.timeout, l.ip, u.ban from log AS l, users AS u where l.token =? AND u.id=l.user_id LIMIT 1") or die($this->db->error);
        $stmt->bind_param("s", $_COOKIE['auth']) or die($stmt->error);
        $stmt->execute() or die($stmt->error);
        $stmt->store_result();
        if ($stmt->num_rows == 0) {
            $this->signout();
        }
        $stmt->bind_result($data['browser'], $data['timeout'], $data['ip'], $data['ban']) or die($stmt->error);
        $stmt->fetch() or die($stmt->error);
        $result = $this->validation->check("protection", $data);
        if ($result != true) {
            $result = (is_numeric($result)) ? $result : true;
            $this->signout($result);
        }
        session_regenerate_id();
        $_SESSION['auth'] = $_COOKIE['auth'];
        $stmt->close() or die($stmt->error);
    }
}

1 个答案:

答案 0 :(得分:1)

似乎没有正确设置域和/或路径:

http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Path

请注意,exam.azwww.ezam.az ...

不同

我猜Path: /core导致问题。