View Full Version : js cookie works on one domain but not another

12-15-2004, 04:52 PM
hi everyone. this is my first attempt "cookie-ing" so thanks in advance. sorry if it's overkill, i've tried to be specific enough to get quick advise!

i set up a cookie with redirection on my domain to test it before setting it up for a client. it works perfectly there. today, i set it up on client's site and it doesn't work right. i've poured through the code, it's the exactly the same except for the name of the cookie.

i've tried clearing my cookies and testing the client's site. originally i copied and pasted the code from my site pages into the client's pages and it was not working, so i renamed the cookie in the client's site. that's the only change i've made.

i can't understand why it works a-ok on one domain and not another.

here's what happens on my - correctly working - domain:
1. visitor goes to http://beersdesign.com/index.htm. as many times as they return, they get this page until they optin.

once they optin, they get the page http://beersdesign.com/webdesign.htm.

2. when webdesign.com loads, it sets a cookie that will last 365 days.

3. next time that person goes to beersdesign.com (the index.htm), the cookie is checked, and if it exists, they are redirected to webdesign.htm. if no cookie, they still get the optin page, index.htm.

this works wonderfully in all my tests. the cookie it sets is --


HOWEVER, the exact same set up (but different cookie name) on investorwealth.com does not work correctly.

1. person goes to http://investorwealth.com/splash3.htm and opts in. they are redirected to http://investorwealth.com/home.htm. cookie is set.

(this url will be the index.htm once it works right and i finish up the page content)

2. if you LEAVE THAT BROWSER window open, surf around to other places, and try to go back to splash3.htm, you get redirected properly to home.htm.

if you close the browser window, open a new one and go to splash.htm, you get the optin page. this should NOT happen for 365 days.

the cookie that is set by home.htm is


obviously this is the problem, but with the coding EXACTLY the same, what is causing the cookie to get set incorrectly on investorwealth.com domain??

thank you. :)

Mr J
12-15-2004, 05:42 PM
Check your cookie functions against these


// An adaptation of Dorcht's cookie functions.

function set_cookie(name, value, expires, path, domain, secure){
if (!expires){expires = new Date()}
document.cookie = name + "=" + escape(value) +
((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
((secure == null) ? "" : "; secure");

function get_cookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg){
return get_cookie_val(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
return null;

function get_cookie_val(offset){
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));

function delete_cookie(name,path,domain){
document.cookie = name + "=" +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
"; expires=Thu, 01-Jan-00 00:00:01 GMT";

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum