如何在php上删除cookie?

时间:2015-12-04 13:13:37

标签: php cookies

我想删除现有的cookie:

header2.php

<?php
if(isset($_POST['logout1']))
    {
        unset($_COOKIE['hr']);
        setcookie("hr", "", time() -3600);
        header("Location: ../index.php");
        return true;
    } ?>

但无法删除Cookie。那有什么问题?

这是我的

hr.php

 <?php 
 include "header2.php";
 $auth = $_COOKIE['hr'];
 header ("Cache-Control:no-cache");
 if(!$auth == "ok") 
 {
 header ("Location: ../index.php");
 }
 ?>
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"    style="background-color: #228B22">
 <ul class="nav navbar-nav navbar-right">
 <li>
 <h4 style = "margin-top:18px; color:#fff;"> HR </h4>
 </li>
 <li>
 <button type="submit" name="logout1">logout</button>
 </li>
 </ul>
 </div>

1 个答案:

答案 0 :(得分:0)

如果有帮助,这是我的一些代码中删除cookie的副本

setcookie('hr', null, -1, '/');