Cookies not being created using JavaScript document.cookie
I must shamefacedly confess to bad programming practice, as I have one page write a cookie and the form handler (a separate PHP file) then reads that cookie. Don't ask me why I am doing this (well, you really should, to expose me for the hack that I am… maybe I will learn something here.
Finally, I narrowed it down in the debugger to when I set the document.cookie object using JavaScript. On the working site (Bluehost), document.cookie gets set to the cookie value. On my Linode environment, using the LAMP stack, it does not. Aargh. FWIW, here's the code:
function formSetCookie(c_name,value,expiredays)
{
var exdate=new Date();
//var sNewVal = value.replace(/ /g,"+");
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) +
"; path=/; domain=worldbento.com";
}
Should path be "/" or something else?
Any ideas appreciated, folks. I am real excited about Linode, but just want my site to migrate seamlessly.
Vik
5 Replies
Checking the page source directly, I find this snippet here:
Basically, it's setting the cookie's domain to "indianbento.com", rather than "worldbento.com". I tried this in Opera, but I'd assume this happens in other browsers as well.
This is why I was asking why you couldn't just remove the domain parameter for the cookie, allowing the browser to handle this part by itself (not setting the domain would just make it valid for the current domain of the web page's URL).
That definitely was the problem. I'm just beginning to learn how to use the Chrome JavaScript debugger better, and didn't even realize that I could put a watch on the variable. It turned out that I had not updated my minified JS file _tracking.js, and so it was using the old domain.
Thank you very much!
Vik