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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.