What could be the reason why the cookie will not be destroyed?

I have a cookie named MVCID that sets and its value is some generated hash. when i write this

setcookie("MVCID","", time()-60*60*24); 

      

and load the page, not only the content of the cookie is not erased, but also does not die.

What could be the problem? this is not the first time this has happened.

ps: im also trying this on a blank page with no other code, but it still wont die.

+1


a source to share


3 answers


Try passing "/" as the fourth parameter - path.



+1


a source


Are you calling this function before outputting any HTML? That's a well-known call header, since cookies have to appear in the HTTP header.

You might want to check the time on the client side as well. Even though you set the expiration date one day ago, it is possible that the clock may be skewed more (if the times are not set correctly).

And I prefer to populate all parameters rather than relying on default values ​​(which can change based on many things).

Alternatively, you can check the return code, although I don't know how this might happen, for example:



<?php
    $ret = setcookie("MVCID","", time()-60*60*24);
?>
<html>
    <head></head>
    <body>
        Hello<br>
        <pre>
            <?php
                print_r ($ret);
            ?>
        </pre>
    </body>
</html>

      

Otherwise, you may need to look at what's going on at the wire level. In other words, check the HTTP response to make sure there are HTTP headers Set-Cookie

and check the actual values ​​passed along with it.

And one last trick to try: delete the cookie completely and exit the browser (some of them are cached in memory). Then try again. If PHP setcookie doesn't work, no cookie will be created - the one you have that doesn't change or hasn't expired can be abandoned from a previous successful version of your code.

0


a source


Use something like firebug or fiddler to check the actual response headers (both the ones containing the "real" cookie and the file containing the "delete" cookie)

0


a source







All Articles