不能删除cookie,我做错了什么?

时间:2016-10-26 06:53:04

标签: php cookies

classlogin.php

/*set cookies*/
            $cookie_name = 'domain[user]';
            $cookie_value = 'domain[authID]';

            // start set cookie //
            //** cookie need to change right away after user press login**//
            // exp  setcookie($cookie_name,'',time()+(60*60*24),'','','',TRUE);
            setcookie($cookie_name,$value,time()+(60*60*24),'/');
            setcookie($cookie_value,$valueID,time()+(60*60*24),'/');

classlogout.php

<?php
    class checkLogout{
        public function __construct(){
            echo $this->logout();
        }

        public function logout(){
            $cookie_name = 'domain[user]';
      $cookie_value = 'domain[authID]';

            if (isset($cookie_name)) {

            unset($_COOKIE[$cookie_name]);
            unset($_COOKIE[$cookie_value]);

            //expire cookie when user click logout
            setcookie($cookie_name, null, -3600, '/');
            setcookie($cookie_value, null, -3600, '/');

            return json_encode($_COOKIE);
        return true;
            } else {
              return false;
            }

        }
    }
$checkLogout = new checkLogout();
?>

我无法移除我的cookie,他们退出同一个文件夹,所以我不认为是路径问题?我使用json_encode检查我的cookie,它不会删除。为什么呢?

1 个答案:

答案 0 :(得分:0)

这是$cookie_name, $cookie_value函数中替换(unset)的方式。它不会取消您正在寻找的cookie

unset($_COOKIE['domain[user]']);
unset($_COOKIE['domain[authID]']);

可能它应该使用下面的代码

unset($_COOKIE['domain']['user']);
unset($_COOKIE['domain']['authID']);