473,781 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookie always return NULL

30 New Member
Hi,

I've written my own JavaScript and used a couple of codes to set and get cookies from the net I found.

When I set the cookie I can see it in my browser, it is set with the right value and expiration date etc. The only problem I'm getting is when I retrieve the cookie the value is always NULL.

Expand|Select|Wrap|Line Numbers
  1. // ==UserScript==
  2. // @name          Utopia Login/Loged
  3. // @namespace     http://games.swirve.com/utopia/login.htm
  4. // @description   Logs your Utopia login
  5. // @include       http://games.swirve.com/utopia/login.htm
  6. // @include       http://u1.swirve.com/enter.cgi
  7. // @include       http://u1.swirve.com/logout.cgi?
  8. // ==/UserScript==
  9.  
  10. var cookie;
  11. var loggedIn = false;
  12. var lastLoginDate;
  13. var lastLoginTime;
  14.  
  15. var currentLocation = location.href;
  16.  
  17. if (currentLocation == "http://games.swirve.com/utopia/login.htm" && loggedIn == false)
  18. {
  19.   cookie = readCookie("utopiaLoginTimer");
  20.   window.alert("Login page : cookie_value: " + cookie);
  21.  
  22.   if (cookie)
  23.   {
  24.     window.alert("Last login date and time: " + cookie);
  25.   }
  26. }
  27. else if (currentLocation == "http://u1.swirve.com/enter.cgi")
  28. {
  29.   window.alert("Logged in");
  30.   loggedIn = true;
  31. }
  32. else if (currentLocation == "http://u1.swirve.com/logout.cgi?")
  33. {
  34.   window.alert("Logged out");
  35.   loggedIn = false;
  36.  
  37.   var date = new Date();
  38.   date.setTime(date.getTime()+(1*24*60*60*1000));
  39.  
  40.   var expires = date.toGMTString();
  41.   createCookie("utopiaLoginTimer", "test_something", 5);
  42. }
  43.  
  44. function createCookie(name,value,days)
  45. {
  46.   if (days)
  47.   {
  48.     var date = new Date();
  49.     date.setTime(date.getTime()+(days*24*60*60*1000));
  50.     var expires = "; expires="+date.toGMTString();
  51.   }
  52.  
  53.   else var expires = "";
  54.   document.cookie = name+"="+value+expires+"; path=/";
  55.  
  56.   window.alert("Cookie created : value : " + value);
  57. }
  58.  
  59. function readCookie(name)
  60. {
  61.   var nameEQ = name + "=";
  62.   var ca = document.cookie.split(';');
  63.   for(var i=0;i < ca.length;i++)
  64.   {
  65.     var c = ca[i];
  66.     while (c.charAt(0)==' ') c = c.substring(1,c.length);
  67.     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  68.   }
  69.   return null;
  70. }
  71.  
  72. function eraseCookie(name)
  73. {
  74.   createCookie(name,"",-1);
  75. }
This is a small script that I'm using with GreaseMonkey for Firefox.

All the If statements work fine and every gets set and displayed but the cookie value is always returned as NULL?

Thanks

P.S. How do I get my current system time, I am GMT+10, the date that comes up in the windows.alert is tomorrows date and 1PM whereas I am at 12AM now.
Oct 14 '07 #1
2 3194
mlevit
30 New Member
Just found out, the code works on:

http://games.swirve.co m/utopia/login.htm

but not on:

http://u1.swirve.com/logout.cgi?

Anyone know the reason why this might be?
Oct 14 '07 #2
dmjpro
2,476 Top Contributor
Just found out, the code works on:

http://games.swirve.co m/utopia/login.htm

but not on:

http://u1.swirve.com/logout.cgi?

Anyone know the reason why this might be?

I think this "http://u1.swirve.com/logout.cgi?" will be "http://u1.swirve.com/logout.cgi"
Simply do remove the "?" then see what happens.

Debasis Jana
Oct 15 '07 #3

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

Similar topics

0
2585
by: Phil Powell | last post by:
URL: http://valsignalandet.com/cookiegrab.php?name=valIdentifier This page produces a cookie value and sends it back as HTML using PHP and Javascript to obtain it. This URL will be used as the value for a URLConnection object in a Java class to obtain the results of this page to get, of all things, a cookie value. Simply put: it's the ONLY way I know of where I can use Java to ultimately obtain a cookie since this is an application...
0
3924
by: Sucpraran | last post by:
We are using Cookies in our application to track user session. It works 95% but fails in occations. We could not find any pattern for this. Below is the code to Set and Get cookies. In the occations when it fails, we get nothing in getCookie as if cookie is not set. We verified Browswer Setting and all of them accept cookies. We try to find a pattern with Broswer types/versions and OS types/versions but could not come with a pattern. ...
5
1991
by: Connie Walsh | last post by:
Hi: I gleaned a javascript off of the web: http://www.hypergurl.com/popup.html that sets a cookie everytime someone visits your site. If it is the first visit in x number of days then a popup will appear. It would be great for my application but I can't get it to work. Here is my code:
4
3821
by: socialism001 | last post by:
I'm trying to store a value in a cookie but its not working. Can anyone see what I might be doing wrong. Thanks, Chris ~~~~~~~~~~~~~~~~~~ <script language="javascript"> if(document.cookie.indexOf("beenHere1=true")!=-1) else
9
4503
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored in a cookie and a small bullit shown in front of the hyperlink, so when I reload the page I can immediately see which hyperlinks I already visited that day.
3
2364
by: Mike | last post by:
I have a web application that the forms authentication cookie is not expiring correctly. When I look at the trace information of a newly requested page after the session and forms authentication have expired the forms authentication cookie is assigned a new value. I am never redirected to the login page after my initial login. If I access the site from http://localhost/myapp instead of myapp.domain.com the cookies expire correctly. The cookie...
1
6718
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to simply pass the values in a cookie to the querystring that would be even easier, but from what I've been able to tell, cookie values can't be passed to a querystring. I'm sure the answer will help alot of others who are using this script, and would...
1
1214
by: bkendra5 | last post by:
I am volunteering at a hospital and working on the intranet. They want an option to have a pop up message but they only want it to pop up once or twice, and then be able to change the content and have it re pop-up. Example: week1 how to properly wash your hands Week2: system wide meeting on thursday dont forget. etc etc.. I am not very good in Java. but this is what i have so far. Can anyone point me in the right direction. Greatly...
3
7789
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.