tags:

views:

44

answers:

3

i have a cookie named MVCID that's set and its value is some generated hash. when i write this

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

and load the page, not only is the contents of the cookie not being erased but it also isn't dying.

what can be the possible problem? this isnt the first time this is happening.

ps: im also trying this on an empty page with no other code but this and it still wont die.

+1  A: 

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

MrKishi
tried that same thing. i guess im going to go to sessions. im starting to hate cookies.
even though sessions are stores like cookies :p hope it works better.
Sessions are *not* stored in the same fashion as cookies. Session storage is maintained on the application server (for PHP, the default is in a temporary file, although this can be modified to use a database, memory-backed store, etc.) In order to preserve the session identifier, the browser often stores it in a session cookie. Session cookies, however, are special, in that they are explicitly deleted by the browser when the session ends (i.e. the window closes) or expires (after a set time period).
Rob
A: 

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

You might want to also check the time on the client side. Even though you're setting to expire one day ago, it's possible that the clock skew might be greater (if times aren't set correctly).

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

In addition, you may want to check the return code although I have no idea how it could fail, something like:

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

Failing that, you may need to have a look at what's going on at the wire level. In other words, examine the HTTP response to ensure there's a Set-Cookie in the HTTP headers and examine the actual values being passed along with it.

And one last trick to try: delete the cookie totally and exit from the browser (some of them cache in memory). Then try again. If the PHP setcookie is not working then no cookie will be created - the one you have that's not being changed or expired may be left over from a previous successful variant of your code.

paxdiablo
nope no html. but hmm let me try lol.
i just passed some html and nothing , its still there.
A: 

Use something like firebug or fiddler to examine the actual response headers (both, the one containing the "real" cookie and the one containing the "delete" cookie)

VolkerK