Home >Backend Development >PHP Tutorial >PHP 如何删除cookies?

PHP 如何删除cookies?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:49:581037browse

<code class="lang-php">setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
setcookie($auth_cookie_name, $auth_cookie, $expire, '/', COOKIE_DOMAIN, $secure, true);
setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, '/', COOKIE_DOMAIN, $secure_logged_in_cookie, true);
</code>

以上代码是生成cookies的

<code class="lang-php">setcookie($auth_cookie_name,'');
</code>

使用上述代码无法清除 name 为 $authcookiename 指定的 Cookies?

求解

回复内容:

<code class="lang-php">setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
setcookie($auth_cookie_name, $auth_cookie, $expire, '/', COOKIE_DOMAIN, $secure, true);
setcookie(LOGGED_IN_COOKIE, $logged_in_cookie, $expire, '/', COOKIE_DOMAIN, $secure_logged_in_cookie, true);
</code>

以上代码是生成cookies的

<code class="lang-php">setcookie($auth_cookie_name,'');
</code>

使用上述代码无法清除 name 为 $authcookiename 指定的 Cookies?

求解

把有效期设置为一个过去的时间可以删除 COOKIE。还有 @MarlinMarlin 说的,

用 xdebug 调试时,session 依然存在。

只要使用了 PHP 的 session_start() 函数,就会产生新的会话,这个和 cookie 无关。调试 cookie 的方法是 firebug 或者 chrome dev tool。

以我的网站为例 http://justjavac.com/

PHP 如何删除cookies?

http://www.php.net/manual/zh/function.setcookie.php

把有效期设置为一个过去的时间就行了

<code>setcookie ($auth_cookie_name, "", time() - 3600);
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn