BleepingComputer.com: Cookie will not set for some reason.

Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cookie will not set for some reason.

#1 User is offline   Ray Parrish 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 91
  • Joined: 30-October 08
  • Gender:Male
  • Location:Cottage Grove, Oregon

Posted 11 March 2010 - 11:51 AM

Hello,

I am having difficulty getting a cookie to be set. I am using the exact same setCookie() code that I use on my web site to set cookies for my skin changing routines to keep the state of any skin change from page to page. For some reason it will not work to set a cookie on the following page -

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

&lt;script type="text/javascript">

// This functions code was lifted right from the W3C tutorial page on cookies.
function setCookie(c_name, value, expiredays) {
	 var exdate = new Date();
	 exdate.setDate(exdate.getDate() + expiredays);
	 document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}

function getCookie(c_name) {
if (document.cookie.length>0)
  {
  var c_start, c_end;
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
	{ 
	c_start=c_start + c_name.length+1;
	c_end=document.cookie.indexOf(";",c_start);
	if (c_end==-1) c_end=document.cookie.length
	return unescape(document.cookie.substring(c_start,c_end));
	} 
  }
return ""
}
function GetElapsedTime(StartStop) {
	 if (StartStop == "Go") {
		  Timer = setTimeout('GetElapsedTime("Go")',1000);
	 }
	 else {
	 Elapsed = Timer.toString()
	 setCookie("ElapsedTime", Elapsed, 365);
	 getCookie("ElapsedTime");
	 document.getElementById('Elapsed1').innerHTML= Timer;
	 }
}
function ExperimentWithDateTime(Hours) {
	FirstDate = new Date();
	document.getElementById('Date1').innerHTML= "First Date - " + FirstDate;
	Time = FirstDate.getTime();
	document.getElementById('Time1').innerHTML= "Time - " + Time;
	  FirstDate.setTime(FirstDate.getTime() + (Hours * 3600 * 1000));
	  document.getElementById('Time2').innerHTML= "Second Date - " + FirstDate;
	  TheDate = FirstDate.toGMTString();
	  document.getElementById('TheDate1').innerHTML= "GMT Date Time - " + FirstDate;
}
function ClockTime() {
	 TheTime=new Date();
	 document.getElementById('Clock1').innerHTML= TheTime;
	 t = setTimeout('ClockTime()',1000);
	 document.getElementById('t1').innerHTML= t;
}
</script>

<style type="text/css">
div.Date {
position: relative;
height: 60px;
width: 250px;
border: solid;
}
div.Time {
position: relative;
height: 60px;
width: 250px;
border: solid;
}
div.TheDate {
position: relative;
height: 60px;
width: 250px;
border: solid;
}
div.Clock {
position: relative;
height: 60px;
width: 250px;
border: solid;
}
div.t {
position: relative;
height: 60px;
width: 250px;
border: solid;
}
div.Elapsed {
position: relative;
height: 60px;
width: 250px;
border: solid;
}
</style>
</head>
<body onload="GetElapsedTime('Go');">

<div class="Date" id="Date1"></div>
<div class="Time" id="Time1"></div>
<div class="Time" id="Time2"></div>
<div class="TheDate" id="TheDate1"></div>

<button onclick="ExperimentWithDateTime(1);">Generate Data</button>

<div class="Clock" id="Clock1"></div>
<button onclick="ClockTime();">Start Clock</button>
<div class="t" id="t1"></div>

<div class="Elapsed" id="Elapsed1"></div>
<button onclick="GetElapsedTime('Stop');">Get Elapsed Time</button>

</body></html>


I know it's not setting the cookie, because I am examining the cookies for the page with the Web Developer tools for Firefox, which has a "View Cookies" menu entry.

Thanks for any help you can be.

Later, Ray Parrish

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users