tags:

views:

156

answers:

1

I'm having trouble expiring a cookie in php. here's my code:

<?php
setcookie('reitinvestor_user', 'null', time()-3600,'',$_SERVER['SERVER_NAME']);
setcookie('reitinvestor_pass', 'null', time()-3600,'',$_SERVER['SERVER_NAME']);
echo '<pre>'; print_r($_COOKIE); echo '</pre>';
exit;
?>

Everytime i hit refresh, I get this result:

Array
(
    [_csuid] => 47dae7b6cd2d9e89
    [reitinvestor_user] => john
    [reitinvestor_pass] => 1f3870be274f6c49b3e31a0c6728957f
    [PHPSESSID] => 6027e370abad115e35b54b0be76befc8
)

I can do a setcookie with different key values and also expire them. I just can't seem to do it for reitinvestor_user and reitinvestor_pass. What's wrong?

+1  A: 

Have you checked whether you are in the same domain and path to change the cookies?

[…] a user agent rejects a cookie (shall not store its information) if any of the following is true:

  • The value for the Path attribute is not a prefix of the request- URI.

  • The value for the Domain attribute contains no embedded dots or does not start with a dot.

  • The value for the request-host does not domain-match the Domain attribute.

  • The request-host is a FQDN (not IP address) and has the form HD, where D is the value of the Domain attribute, and H is a string that contains one or more dots.

RFC 2109

Gumbo
yup, that was the problem, thanks
John