473,406 Members | 2,549 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,406 software developers and data experts.

setting cookies across subdomains or paths

I am setting a cookie on a subdomain:
http://store1.mydomain.com

Then the store takes me to a shopping cart that is at:
http://shopping.mydomain.com

Somewhere the following code (taken and modified from The JavaScript Source)
is broken between domains, because when I click my "store" link that should
read the cookie and send me to store1.mydomain.com or storeN.mydomain.com I
get the default template store.

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->

<!-- Begin
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (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 getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var favorite = GetCookie('store');

if (favorite != null) {
switch (favorite) {
case 'store1' : url = 'http://store1.mydomain.com/';
break;
case 'store2' : url = 'http://store2.mydomain.com/';
break;
case 'store3' : url ='http://store3.mydomain.com/';
break;
case 'storeN' : url = 'http://storeN.mydomain.com/';
break;
}
window.location.href = url;
}
// End -->
</script>
</HEAD>

The cookie is set by a javascript "onload command" Like I said I have it
working on a server with no sub domain.

Any help would be truly appreciated.

Jose Olivas
Jul 23 '05 #1
1 3441
*** Jose Olivas wrote/escribió (Mon, 14 Mar 2005 23:30:18 -0700):
I am setting a cookie on a subdomain:
http://store1.mydomain.com

Then the store takes me to a shopping cart that is at:
http://

Somewhere the following code (taken and modified from The JavaScript Source)
is broken between domains


I couldn't find the line where you set the cookie value. Anyway, there're a
couple of things about cookies that must be taken into account:

1) Cookies are per-domain settings: they're only sent by browser to pages
in the domain they're attached to. If you need a cookie to be valid in more
than one domain then you need to set more than one cookie, one per domain.

2) Many browsers are configured to discard cookies for third-party domains.
So if you set a cookie at store1.mydomain.com for shopping.mydomain.com
they cookie will most likely be lost.

If you have access to a server-side language you may consider using
sessions or databases.
--
-- Álvaro G. Vicario - Burgos, Spain
-- Don't e-mail me your questions, post them to the group
--
Jul 23 '05 #2

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

Similar topics

2
by: Keon | last post by:
Hoi Is it possible to use cookies between different domains? For my site I use 2 domains; the first for my global site with ASP en HTML the second is for my forum located on "hyperboards" a...
2
by: Raterus | last post by:
Howdy, I have one IIS Application, with asp/asp.net pages. I set a cookie like so in an ASP page. Response.Cookies("AuthCookie")("hash") = md5(username & Application("HashCode"))...
2
by: Tariq | last post by:
Hi, Is it possible to pass cookies across sites? for instance i want to pass a session id from htp://server1 to http://server2. If I follow the code snippet below HttpCookie cookie = new...
5
by: Shane Thomas | last post by:
Hello, I'm having difficulty handling cookies with paths other than "/". An HttpWebRequest object returns these headers: Date: Tue, 26 Apr 2005 21:29:39 GMT Server: Apache/1.3.33 (Unix)...
4
by: Vlad Dogaru | last post by:
Hello, I am trying to use cookies and Python to create a simple login example. But I am very disoriented at the existence of two cookie libraries, namely Cookie and cookielib. I have seen...
1
by: stillworkingfortheman | last post by:
I'm loosing cookies in IE6 (works in firefox) when with the following steps... step 1. set a cookie in one domain, in an .aspx.cs codebehind... in www.domain.com/subdomain1/page1.aspx...
1
by: loooser | last post by:
Hi, I would just like to know if there is a way to let php keep sessions accross subdomains? I mean sessions with cookies, where the domain should be correctly set. Or maybe I can use SID...
0
by: OG | last post by:
Hello, I would like to share cookies across various web based apps, and from what I understand your apps can do this as long as they all belong to the same domain. For example app1.mydomain.com...
1
by: daniel.westerberg | last post by:
Is it possible to keep sessions between subdomains? I.e If I have a site "shop.com" and when user acess his personal page it's "secure.shop.com" Is it possible to share the session values between...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
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,...

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.