/    Sign up×
Community /Pin to ProfileBookmark

JavaScript Cookies

Using this javascript cookie tutorial

[url]http://www.quirksmode.org/js/cookies.html[/url]

to add some security around a section of my companies website. To be honest the security is not to be too rigid. It’s basically just to double check that people can’t enter this section without agreeing to our terms and agreements. So what I did was put this piece of code

var x = getCookie(“BetterWayTest”);
if (x)
{ }
else
{ redirection(); }

into a file. What it does is check for the cookie called BetterWayTest which won’t exist when the person first enters the page. They’re then redirected using a function in this file

[url]http://www.abetterway.co.uk/js_nav/secure.js[/url]

They’re directed to a page where they have to click accept which then creates the cookie and then lets the person browse that section of the site. And it works. No problems, everythings fine and we’re all happy.

But now I’m trying to reproduce the same files on our dev server for another site and when the first function redirects them the cookie thats been created is gone….

this line in the redirection function is called

createCookie(“OnTheWayTo”,document.URL,0);

and the cookies there, but then when this line is called

self.location.href = “http://www.abetterway.co.uk/adviser/adviser_disclaimer.html“;

it’s gone….
weird thing is though if I create a page on the same directory as the disclaimer page it works. If I put it in a directory it doesn’t.

ANY tips is appreciated with this weird one, thanks ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliMar 20.2007 — 
weird thing is though if I create a page on the same directory as the disclaimer page it works. If I put it in a directory it doesn't.[/QUOTE]
The [I]path[/I] parameter determines the highest folder level at which the cookie can be read. If not specified, it defaults to the current.
Copy linkTweet thisAlerts:
@RabBellauthorMar 20.2007 — The [I]path[/I] parameter determines the highest folder level at which the cookie can be read. If not specified, it defaults to the current.[/QUOTE]

aaaahhhh, that explains it all...thanks ?
×

Success!

Help @RabBell 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 6.13,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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