0

The following code works fine in IE8 and Firefox 3.5. Any idea why it does not work in Chrome ? Tried it both in localhost and on my web server -- no success.

In the header:

<?php
   if((isset($_COOKIE["unique_id"]))&&isset($_COOKIE["users_resolution"])){
      $screen_res = $_COOKIE["users_resolution"];
      $unique_id = $_COOKIE["unique_id"];
   }
   else //means cookie is not found set it using Javascript
   {
      ?>
<script language="javascript">
			<!--
			writeCookie();
			function writeCookie()
				{
				var today = new Date();
				var the_date = new Date("December 31, 2023");
				var the_cookie_date = the_date.toGMTString();
				var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
				var the_cookie = "unique_id="+ uniqid();
				var the_cookie = the_cookie + ";expires=" + the_cookie_date;
				document.cookie=the_cookie
           			}
			function uniqid()
			  {
			  var newDate = new Date;
			  return newDate.getTime();
			  }
			//-->
		</script>
<?php } ?>

// And in the ,body>

         <?php
	echo "Screen resolution: ".$screen_res."<br>";
	echo "Unique ID: ".$unique_id."<br>";
	?>

Any help would be appreciated.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by fxm
0

The following code works fine in IE8 and Firefox 3.5. Any idea why it does not work in Chrome?

I haven't tested the javascript part of the code in Chrome yet, but the first place I would look would be the Cookies tab at
Tools | Options | Under the Hood | Privacy [Content settings...]

0

It isn't obvious how this

var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
var the_cookie = "unique_id="+ uniqid();
var the_cookie = the_cookie + ";expires=" + the_cookie_date;

could be working in any browser. For starters, the second assignment obliterates the first.

Try something like this

var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
    the_cookie += ";unique_id="+ uniqid();
    the_cookie += ";expires=" + the_cookie_date;

instead.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.