[thelist] any JS cookie experts out there?
Tom Dell'Aringa
pixelmech at yahoo.com
Mon Dec 16 15:54:00 CST 2002
I've got this job where I am working some of my own PHP pages into
Kurant StoreSense, which I believe runs on PowerBuilder.
My pages are php, so the user pops into my pages to register, and
then I need to write some cookie info in JS to it gets passed along
as they work in StoreSense.
So when the person registers, I write this:
document.cookie = "data=<?=$data?>";
And the cookie is there. If I pop around in my php pages in that
directory, I can get an alert with the cookie data every time, no
problem.
Now, I have a link on one of my pages that sends the user back into
the store, which would look something like this:
http://www.domain.com/Page.bok?template=Some%20Gifts
And mysteriously, my cookie is GONE, kaput. I had a person over at
the ISP trying to help out, and he said it was because my cookie was
expiring at end of session - but I am NOT ending the session! I'm
moving to another page. I'm not closing the browser or anything.
Here is the code I am using to pull the cookie on all my pages, taken
directly from the JS Bible by D. Goodman, the man.
function getCookieData(labelName)
{
var labelLen = labelName.length;
// read cookie property only once for speed
var cookieData = document.cookie;
var cLen = cookieData.length;
var i = 0;
var cEnd;
while(i < cLen)
{
var j = i + labelLen;
if(cookieData.substring(i,j) == labelName)
{
cEnd = cookieData.indexOf(";", j);
if(cEnd == -1)
{
cEnd = cookieData.length;
}
return unescape(cookieData.substring(j+1, cEnd));
}
i++
}
return "";
}
Then to view it I am simply doing:
function init()
//check and see if cookie exists
{
data = getCookieData("data");
if(!data == "")
{
alert('cookie = ' + data)
}
}
---------
Any ideas why this would fail? I've tried setting a expiration date
years from now which doesn't seem to be working either. Support says
StoreSense doesn't delete any cookies, and I believe him. But I
wonder if something else may be going wrong or I am not coding this
right. I have used this same code in another project and it worked
fine..
Tom
=====
var me = tom.pixelmech.webDeveloper();
http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
More information about the thelist
mailing list