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.

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...]

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.