Click to See Complete Forum and Search --> : cookies not available across pages


j_ford
01-05-2004, 01:23 PM
Hi, all:

Newcomer to the forum.

In a localhost web app, I have set a cookie on page 1 and am trying to read it in page 2. It's not working.

Page one calls this JavaScript function:

function doChoice(project, choice)
{
if(choice == "configure")
{
document.cookie = "current_project=" + project + "; path=/";
}
}

Page two includes this:

<script language="JavaScript">
<!--
var cookies = document.cookie;
var search = "current_project=";
var start = cookies.indexOf(search);

...

-->
</script>

But cookies is always an empty string when read from page 2, and so start always shows as -1.

I've tried setting the cookie with and without "path=/" but it doesn't work either way.

I'm using a Mozilla 1.5 browser on a Red Hat 9.0 Linux box; webapp is deployed in a Tomcat web server. Access is through Apache using mod_jk.

Mozilla's cookie manager shows current_project as a valid cookie, with content.

Any ideas what's wrong?

Thanks.

Jerry

Khalid Ali
01-05-2004, 05:37 PM
Take a look at this link (http://www.webapplikations.com/pages/html_js/document/SimpleLoginCookieScript.html)
It should clarify some cookie related problems.

j_ford
01-05-2004, 06:30 PM
Khalid:

Now I see it. Some experimentation confirms, an expiration time is required. I thought I read in my reference docs that the only absolutely firm requirement is name=value.

But I can't make it work across pages without an explicit expiration some time in the future.

Thanks.

Jerry

Khalid Ali
01-05-2004, 08:28 PM
My pleasure...glad to be of any help
:D

jedioutcaster
01-05-2004, 11:58 PM
A certain time limit doesn't give that much help when you don't know if the user wants to test your page for the time limit. Well, maybe I'm wrong, but if your using PHP or something, you can try to carry the cookie name across pages through PHP. A little trouble, but it works.

:)