概述
php删除/清除cookie的两种方法
将cookie的值设置为空,即:setcookie('cookiename', '')或者setcookie(cookiename, NULL);
将cookie的过期时间设置为过去,即:setcookie('cookiename','',time()-3600);
方法一:将cookie的值设置为空
setcookie ( "cookie_user", "test", time () + 60 * 60 * 24 * 30 );
setcookie ( "cookie_pass", md5 ( "test" ), time () + 60 * 60 * 24 * 30 );
function logout() {
setcookie ( "cookie_user", "", time () + 60 * 60 * 24 * 30 );
setcookie ( "cookie_pass", "", time () + 60 * 60 * 24 * 30 );
}
/* http://www.manongjc.com/article/1253.html */
logout ();
echo $_COOKIE ['cookie_user'] . "
";
echo "You have successfully logged out.";
?>
第二种方法:将cookie的过期时间设置为过去
setcookie ( "cookie_user", "test", time () + 60 * 60 * 24 * 30 );
setcookie ( "cookie_pass", md5 ( "test" ), time () + 60 * 60 * 24 * 30 );
function logout() {
setcookie ( "cookie_user", "test", time () - 100 );
setcookie ( "cookie_pass", md5 ( "test" ), time () - 100 );
}
logout ();
echo $_COOKIE ['cookie_user'] . "
";
echo "You have successfully logged out.";
?>
最后
以上就是糊涂电话为你收集整理的php中清除cookie_php删除/清除cookie的两种方法的全部内容,希望文章能够帮你解决php中清除cookie_php删除/清除cookie的两种方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复