473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript: How do you set / read cookies with Chrome

The following code works with both IE8 and Firfox 3.5. Any idea why I can't read these values when I use Chrome ? (I have tested using both a localhost server and my remote web server, with both my computer and another in the house.)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.       <title>Cookie Test</title><?php
  4.         if((isset($_COOKIE["unique_id"]))&&isset($_COOKIE["users_resolution"])){
  5.         $screen_res = $_COOKIE["users_resolution"];
  6.         $unique_id = $_COOKIE["unique_id"];
  7.         }
  8.         else //means cookie is not found set it using Javascript
  9.         {
  10.         ?>
  11.  
  12.       <script language="javascript">
  13.             <!--
  14.             writeCookie();
  15.             function writeCookie()
  16.                 {
  17.                 var today = new Date();
  18.                 var the_date = new Date("December 31, 2023");
  19.                 var the_cookie_date = the_date.toGMTString();
  20.                 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
  21.                 var the_cookie = "unique_id="+ uniqid();
  22.                 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
  23.                 document.cookie=the_cookie
  24.  
  25.                 // location = 'test.php';
  26.                 }
  27.             function uniqid()
  28.               {
  29.               var newDate = new Date;
  30.               return newDate.getTime();
  31.               }
  32.             //-->
  33.         </script>
  34.         <?php } ?>
  35.     </head>
  36.     <body>
  37.         <?php
  38.         echo "Screen resolution: ".$screen_res."<br>";
  39.         echo "Unique ID: ".$unique_id."<br>";
  40.         ?>
  41.     </body>
  42.     </html>
  43.  
Jun 10 '10 #1
2 8229
acoder
16,027 Expert Mod 8TB
Try it with something simple first. See http://www.quirksmode.org/js/cookies.html
Jun 21 '10 #2
Makes sense. Will do. Thanks for the reply !
Jun 21 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Duncan | last post by:
Hi I'm doing a site that creates a cookie and then needs to read that cookie later. The cookie is created fin and I can see it in my browsers cookies but I can't seem to read it. I've tried...
0
by: bb | last post by:
Hello In my Session_OnStart in Global.asa, I am setting some cookies. One of them, I set as follows: dim UserID UserID = Request.ServerVariables("LOGON_USER") Response.Cookies("User")("ID")...
2
by: jack | last post by:
Hello, I am using Form Based Authentication. The Authentication Ticket/Cookie works, and I set a second cookie for storing other settings. The second cookie is not working on some PCs. I...
2
by: Wardeaux | last post by:
I set a cookie in my code behind: Dim cookieFocus As New HttpCookie("PMFocus") cookieFocus.Value = "D" Response.Cookies.Add(cookieFocus) I read the cookie in my html page: function...
0
by: csgraham74 | last post by:
Hi guys, I am writing an application in asp.net but im attempting to write some client side validation. I have most of this working but i am having trouble reading cookies set in asp.net using...
4
by: oopaevah | last post by:
What are the pitfalls of passing a token in the url once a user is logged on so I can remember who they are? I can easily implement this by adding &token=abcdefghijklmnop123 to each internal...
3
by: gencode | last post by:
I need to make a javascript read a web directory from a remote site (ie "http://remotesite.com/images") (The remote die does not have an index.htm and does have directory listing enabled) I...
1
by: Rodolo | last post by:
Hi, I use Javascript cookies in a web application with a command like this document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" +...
0
by: catoblepa80 | last post by:
How can i read all google chrome bookmarks and place it into a list or a dictionary? i think the best way is to use regular expressions on the chrome bookmarks file, can you help me to accomplish...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.