0

我正在设置一个cookie,如下所示:

if($persist=='persist'){ //  if remember me then set long cookie expiration

        setcookie("aukCookie", "$user", time()+9900000, "/", "myurl.com");
        setcookie("aukCookie2", "$username", time()+9900000, "/", "myurl.com");
        setcookie("AUKpersist", "$user", 0, "/", "myurl.com");

    } else {

        setcookie("aukCookie", "$user", time()+86400, "/", "myurl.com");
        setcookie("aukCookie2", "$username", time()+9900000, "/", "myurl.com");

    }

然后删除我去同一个文件与 url 变量?logoff=true

然后我尝试以下方法:

if ($_GET[logoff]=='true'){
    setcookie ("aukCookie", "", time()-3600, "/", "myurl.com"); 
    setcookie ("AUKpersist", "", time()-3600, "/", "myurl.com"); 
    // use below to send user somewhere when logged out successfully
    header("Location: /userAdmin/userlogin.html?loggedOut"); 
}

但是cookie根本没有被删除。该header()功能工作正常。

有任何想法吗?有一个更好的方法吗?

4

4 回答 4

2

尝试设置 null 而不是空,例如:

if ($_GET[logoff]=='true'){
    setcookie ("aukCookie", NULL, time()-3600, "/", "myurl.com"); 
    setcookie ("AUKpersist", NULL, time()-3600, "/", "myurl.com"); 
    // use below to send user somewhere when logged out successfully
    header("Location: /userAdmin/userlogin.html?loggedOut"); 
}
于 2013-03-18T12:13:18.263 回答
1

请尝试unset

IE,

unset($_COOKIE["aukCookie"]);

它会工作

于 2013-03-18T12:15:52.640 回答
0

尝试

setcookie("aukCookie", "", -1, "/", "myurl.com");
于 2013-03-18T12:17:23.300 回答
-1

删除 cookie

bool setcookie ( 字符串 $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]])

setcookie ("mycookiename", "", time() - 3600);

另一个例子

setcookie("mycookiename", $value, time()+3600, "/~rasmus/", "example.com", 1);

测试一下

enter code here // Print an individual cookie

enter code here echo $_COOKIE["mycookiename"]; echo $HTTP_COOKIE_VARS["mycookiename"];

// Another way to debug/test is to view all cookies print_r($_COOKIE); 这是设置 cookie 的概念

注销的情况下,您需要取消设置cookie,如下例所示

unset($_COOKIE['mycookiename']);

像这样的东西

if ($_GET[注销]=='true'){

未设置($_COOKIE['aukCookie']);

未设置($_COOKIE['AUKpersist']);

header("位置:/userAdmin/userlogin.html?loggedOut");

}

于 2013-03-18T12:30:01.290 回答