php刪除cookies的方法:1、使用「setcookie('cookiename', '')」方法將cookie的值設為空白;2、透過「setcookie('cookiename','',time( )-3600);”方法。
推薦:《PHP影片教學》
php刪除/清除cookie的兩種方法
將cookie的值設為空,即:setcookie('cookiename', '')或setcookie(cookiename, NULL);
將cookie的過期時間設為過去,即:setcookie ('cookiename','',time()-3600);
方法一:將cookie的值設為空白
<?php 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'] . "<br />"; echo "You have successfully logged out."; ?>
第二種方法:將cookie的過期時間設定為過去
<?php 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'] . "<br />"; echo "You have successfully logged out."; ?>
以上是php如何刪除cookies的詳細內容。更多資訊請關注PHP中文網其他相關文章!