473,382 Members | 1,705 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,382 software developers and data experts.

Cookie does not appear to store properly

The purpose of my application is to require a website visitor to complete
a form before participating in a search application. I have a specific
reason for doing this with client-side javascript, but I'm not going to
go into the explanation of "why."

Ideally, the visitor goes to http://www.hopelandinc.com/golf-homes.html.
If they haven't registered in 90 days, they'll be redirected to a
registration form. Once they complete the reg form, they'll have a cookie
set (called "isRegistered") and be taken back to the golf homes page.

For testing purposes, it is not necessary to actually complete the form.
You can go to the golf-homes.html page, which will set the regReturn
cookie, and then bypass the form submission by going directly to
http://hopelandinc.com/registration-thanks.html

In short, it ain't working. (IE 6 test).

golf-homes.html calls the function securePage() below, which sets
regReturn and redirects to search-registration.html.

search-registration is a form that posts to an ASP script, then redirects
to registration-thanks.html

registration-thanks.html calls the function addRegistrationCookie which
adds the isRegisteredCookie, and then redirects to the value stored in
regReturn.

I've been trying to figure out why it doesn't work all day, and can't
find the problem. Hopefully some super-genius here will be able to help!

TIA, code below

Ziggy

Here is the function I'm using to retrieve a cookie value ("regReturn")
and redirect to a specified web page:

function addRegistrationCookie() {
var now= new Date();
var expDate = new Date(now.setDate(now.getDate() + 90));
expDate = expDate.toString();
makeCookie("isRegistered", "exists", expDate)
if (readCookie("regReturn")!='none') {
this.window.location.href = readCookie("regReturn");
}
}

The cookie is created when this function is called:

function securePage(cName, rLink) {
var now = new Date();
var expDate = now.setDate(now.getDate() + 90);
expDate = expDate.toString();
var loc = this.window.location.href;

makeCookie("regReturn", loc, expDate);

if (readCookie(cName)!="exists") {

this.window.location.href=rLink;
}
}

If I test the makeCookie function, it appears to store the cookie. Here
is the function:

function makeCookie(cName, cVal, cexpDate) {

document.cookie = cName + "=" + cVal +"; expires=" + cexpDate;
}

But when I try to read the cookie, I get no value. Here is the reader
(called on another web page)

function readCookie(cName){
var allcookies = document.cookie;
cName = cName + "=";
var pos=allcookies.indexOf(cName);
var retVal = "none";
if (pos!=-1) {
var start=pos+cName.length;
var end=allcookies.indexOf(";", start);
if(end==-1) end = allcookies.length;
var value=allcookies.substring(start, end);
value=unescape(value);
retVal=value;
}
return retVal;

}
Jul 23 '05 #1
4 1702
Ziggy <ha*******@sitetamer.com> wrote in
news:1118349765.ed857fe97a50d81e3c163c1c04439390@t eranews:
In short, it ain't working. (IE 6 test).


I have tested the code in FireFox and Netscape 7.1, and it works fine
there. Only problem appears to be in IE.
Jul 23 '05 #2

On Thu, 09 Jun 2005 13:42:45 -0700, Ziggy <ha*******@sitetamer.com> wrote:

Give the makeCookie a domain= argument for the cookie domain, if none is
given when making a cookie, it defaults to current page and will not give
access to others in the same domain, like ../ or / or so.

Danny
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #3
VK
There is not such property as navigator.cookieenabled

*But* there is such property as navigator.cookieEnabled (value
false/true)

Edit this and it will work.

Jul 23 '05 #4
Danny <da*******@bluebottle.com> wrote in
news:1118371237.724e05f67cf7e0c9b52e487f19b568fe@t eranews:

On Thu, 09 Jun 2005 13:42:45 -0700, Ziggy <ha*******@sitetamer.com>
wrote:

Give the makeCookie a domain= argument for the cookie domain, if
none is
given when making a cookie, it defaults to current page and will not
give access to others in the same domain, like ../ or / or so.

Danny


Thanks to Danny and VK for their responses. However, I have tried both
suggestions, and the script still fails to keep the regReturn cookie. I've
also tried clearing all cookies from my browser, to make sure I'm not
dealing with a cookie limit issue. Here is the full code of my cookie
functions as they exist now. Anyone else wanna give it a shot?

Incidentally, I'm not even using the checkCookies function in the pages
where I'm having the problem. My script is successfully storing all of the
other cookies.

TIA!

Ziggy

function checkCookies() {
var cookieEnabled=(navigator.cookieEnabled)? true : false

//if not IE4+ nor NS6+
if (typeof navigator.cookieEnabled=="undefined" &&!cookieEnabled){
document.cookie="testcookie"
cookieEnabled=(document.cookie.indexOf("testcookie ")!=-1)? true :
false
}

return cookieEnabled;
}

function readCookie(cName){
var allcookies = document.cookie;
cName = cName + "=";
var pos=allcookies.indexOf(cName);
var retVal = "none";
if (pos!=-1) {
var start=pos+cName.length;
var end=allcookies.indexOf(";", start);
if(end==-1) end = allcookies.length;
var value=allcookies.substring(start, end);
value=unescape(value);
retVal=value;
}
return retVal;

}

function securePage(cName, rLink, cDomain) {
var now = new Date();
var expDate = now.setDate(now.getDate() + 90);
expDate = expDate.toString();
var loc = this.window.location.href;

makeCookie("regReturn", loc, expDate, cDomain);

if (readCookie(cName)!="exists") {

this.window.location.href=rLink;
}
}

function makeCookie(cName, cVal, cexpDate, cDomain) {

// alert(cName + "=" + cVal +"; expires=" + cexpDate);
document.cookie = cName + "=" + cVal +"; expires=" + cexpDate
+";path='/';domain=" + cDomain;
document.cookie = cName + "=" + cVal +"; expires=" + cexpDate
+";path='/';domain=sitetamer.net";
}

function deleteCookie(cName, cDomain) {
var now= new Date();
var expDate = new Date(now.setDate(now.getDate() - 365));
expDate = expDate.toString();
// alert(expDate);
makeCookie(cName, 'none', expDate, cDomain);
makeCookie(cName, 'none', expDate, 'sitetamer.net');
// alert(readCookie(cName));
}

function addRegistrationCookie(cDomain) {
var now= new Date();
var expDate = new Date(now.setDate(now.getDate() + 90));
expDate = expDate.toString();
makeCookie("isRegistered", "exists", expDate,cDomain)
if (readCookie("regReturn")!='none') {
this.window.location.href = readCookie("regReturn");
}
}
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Sims | last post by:
Hi, I am using setcookies to store one single value. But i was reading http://za2.php.net/manual/en/function.setcookie.php and i noticed that a cookie might not be accepted yet it might return...
5
by: | last post by:
I attempted to find the cookie 'Prospect' in my Temp Internet Files in IE6 after I had set it in ASP: Response.Cookies("Prospect").Expires = Date() + 2 Response.Cookies("Prospect")("u_id") =...
2
by: Clive Swan | last post by:
Hi, I have found a few scripts that write user preference to a cookie. I still cannot access the cookie to get user preferences. Also to 'hide' the input form once a user has selected them. ...
3
by: Karsten Grombach | last post by:
Hi, I'm trying the following: - Imitate a Logon using a Post with HttpWebRequest on remote Webserver (asp 3.0 page using https) - On success redirect to the page (encapsuled in an iframe)...
0
by: Michael | last post by:
I have a problem here that only seems to happen on the one new server that we are migrating our ASP.Net application to. The server is a Windows 2000 SP4 box. It initially had the .Net Framework...
2
by: Earl Teigrob | last post by:
I am trying to find storage mechanism that will store a variable until the browser window is closed. A query string variable would be my first choice for this but that is not easily done in my...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
3
by: Dan | last post by:
Hi, I am trying to refresh the cookie to make sure the timeout is reset by simply calling a blank page on my site. I am doing this because I have an external site hosted in my web that isn't...
2
by: fb | last post by:
Hi everyone. I'm planning to store the current date and time in a cookie and then compare, the time in the cookie to the current time. If 30 minutes elapses, then I will ... I dunno ... redirect...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.