benphp Posted February 24, 2011 Share Posted February 24, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/228731-any-problem-with-writing-a-cookie-with-aspvb-but-deleting-with-php/ Share on other sites More sharing options...
Psycho Posted February 24, 2011 Share Posted February 24, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/228731-any-problem-with-writing-a-cookie-with-aspvb-but-deleting-with-php/#findComment-1179253 Share on other sites More sharing options...
benphp Posted February 24, 2011 Author Share Posted February 24, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/228731-any-problem-with-writing-a-cookie-with-aspvb-but-deleting-with-php/#findComment-1179254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.