/    Sign up×
Community /Pin to ProfileBookmark

Hi!
I made a website for a client 2 years ago, and the guys had the great idea of putting the website on a subdomain. I had a cool cookie system, that allowed the user to choose between four different styles. Now I have a problem with my cookie system. The cookie is created on :
blog.domain.com
and apparently it’s read on domain.com, so it’s not found. I searched everywhere, but I don’t know how to specify that it has to look inside blog.domain.com.
That’s the cookie called styleName that I’m talking about. It was situated at domain.com and it worked flawlessly, and now its at blog.domain.com and it’s considered as empty by my code…
Here is my code :

[code=php]<?php
if (!empty($_COOKIE[‘styleName’])) { ?>
</noscript>

<script type=”text/javascript” language=”javascript”>
var currentStyle = getDataCookie(‘styleName’);
document.write (‘<link rel=”stylesheet” title=”default” type=”text/css” href=”http://www.millesaisons.fr/millesaisons/wp-content/themes/default-fr/’ + currentStyle + ‘.css” />’);

</script>[/code]

Yeah, there is some javascript involved…
Thanks for all advice !

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 30.2010 — If I understand the issue correctly, when you set the cookie, if you specify the domain as ".domain.com" (note the leading "."), then it will be sent for all sub-domains and also if no sub-domain is entered for the URL.
<i>
</i>setcookie('cookie_name', 'value', 0, 'cookie/path', [color=red][b]'.domain.com'[/b][/color]);
Copy linkTweet thisAlerts:
@Ness_du_FratauthorAug 30.2010 — Thanks NogDog, but I'm not sure where I should put my '.domain.com'... I'm really not good at javascript, I'm more of a php person, and it's been two years since I browsed the internet to find pieces of code that I put together ^^ Here is my file :
[code=html]// JavaScript Document
function getWholeCookie(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 argLength = arg.length;
var cookieLength = document.cookie.length;
var i = 0;
while (i < cookieLength) {
var j = i + argLength;
if (document.cookie.substring(i,j) == arg) {
return getWholeCookie(j);
}
i = document.cookie.indexOf(' ',i) + 1;
if (i==0) break;
}
return '';
}


function setCookie(name,value,expires,path) {
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" );
}


function tossCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function getDataCookie(cookiename) {
var data = '';
if (navigator.cookieEnabled) data = getCookie(cookiename);
if (data == '') data = 'fantasy';
return data;
}
function getDataCookiedim(cookiename) {
var data = '';
if (navigator.cookieEnabled) data = getCookie(cookiename);
if (data == '') data = 'style';
return data;
}
function changeStyle(newStyle) {
if (navigator.cookieEnabled) {
setCookie('styleName',newStyle,31,'/');
location.href = self.location;
}
else alert ('Vous avez besoin d'activer javascript pour profiter pleinement du site');
}
function changeStyledim(newStyle) {
if (navigator.cookieEnabled) {
setCookie('styleNamedim',newStyle,31,'/');
location.href = self.location;
}
else alert ('Vous avez besoin d'activer javascript pour profiter pleinement du site');
}

function lien(nom,src) {
document.images[nom].src=src;}[/code]
Copy linkTweet thisAlerts:
@NogDogAug 30.2010 — I was thinking along PHP lines, and setting a cookie in the server-side script. When it comes to JavaScript, I'd have to google it myself. ?
×

Success!

Help @Ness_du_Frat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...