Whats wrong with my cookie script...

T

Tommy Lang

Hi I have problem with my cookie script.
I can not understand why this doesn't work. I can set a cookie but
when I try to read it I get "undefined".
Please help,
Tommy


****code*****
//Set a new cookie
function setCookie(name, value)
{
var cookieName = name;
var cookieValue = value;

if(cookieName == "" || cookieValue == "")
{
alert("En cookie måste både ha ett namn och ett värde.");
return false;
}
else
{
//Skapa variabler med sluttid och sökväg
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth()+6);
var path = "/~tf031158"

//Skriv cookie
document.cookie = cookieName + "=" + cookieValue + "; expires=" +
expireDate.toGMTString() + "; Path=" + path;
return true;
}
}




//Read a cookie
function getCookie(name)
{
var thisCookie;
var thisCookieName = "";
var thisCookieValue = "";

if (document.cookie == "")
{
document.write("No cookies to be found");
return false;
}
else
{
thisCookie = document.cookie.split("; ");
for (i=0; i<thisCookie.length; i++)
{
thisCookieName = thisCookie.split("=")[0];
if(thisCookieName == name)
{
thisCookieValue = thisCookie.split("=")[1];
return thisCookieValue;
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top