Jump to content

Any problem with writing a cookie with ASP/VB but deleting with PHP?


benphp

Recommended Posts

I'm writing a cookie using VB in an ASPX file:

 

username = "myname"
If Request.Cookies("username") Is Nothing Then
    Response.Cookies.Set(New HttpCookie("username", username))
Response.Write("newcookie <br />")
Else 
    Response.Cookies.Set(Request.Cookies("username"))
Response.Write("not nothing <br />")
End If

Response.Cookies("username").Expires = DateTime.Now.AddYears(1)

 

and I can read it in PHP:

 

if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
}

 

But when I kill it with PHP ...

 

if (isset($_COOKIE['username'])) {
setcookie ("username", NULL, time()-3600*24*300 ); //300 days
unset($_COOKIE["username"]); 
}

 

... the VB in the ASPX file still sees it and thinks it's an empty string, since it returns:

 

"not nothing"

 

It would seem that the cookie is still alive somewhere, no? And how do I kill it completely, so that the VB writes a new cookie with the same name?

Link to comment
Share on other sites

Well according to the PHP manual for cookies

 

expire:

The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).

 

So, I'm guessing the browser has to be closed before the cookie gets unset?

 

 

EDIT: Also in the manual

Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client. This is internally achieved by setting value to 'deleted' and expiration time to one year in past.

 

So, if the aspx process is setting any of the optional parameters automatically you would need to include those in the call trying to unset the cookie. Also, in the line where you try to delete the cookie try setting the value to boolean false instead of NULL as there is another refernce that using boolean false can also delete a cookie.

Link to comment
Share on other sites

But I set it to expire in the past - not zero.

 

I just tried it after closing the browser, but the VB still reads a cookie - "not nothing".

 

It also still shows up in PHP:

 

if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
print "$username not nothing.";
}

 

$username is blank, but it isn't nothing.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.