/    Sign up×
Community /Pin to ProfileBookmark

Customising Cookie-redirect script

I have found a great little script [URL=”http://javascript.internet.com/cookies/cookie-redirect.html”]http://javascript.internet.com/cookies/cookie-redirect.html[/URL] and have managed to customise it to suit my needs.
However I do need to do one more thing and I am seeking help to do it.

I will explain what i want to do using the default values and links in the example on the above site rather than my customised version to avoid confusion.

So in the example once you choose say “Dog” when ever you go to the original page you get redirected to the page “dog.html” until your cookie expires. That’s all well and good however, after your cookie expires, if you still have “dog.html” bookmarked or type the address directly into the browser you can still visit the page. I want to be able to “dog.html” check for the cookie and if it is not there have it redirect you back to the original page where you make the choice in the first place.

I hope you understand my question. If not have a look at the source (from the link above) first and you should see what I am talking about.

//Don’t read this unless you still don’t know what I am asking. It may confuse you otherwise.
To help clarify I will explain what I am doing with this script. I have adapted the script to use for a disclaimer on an investment site. Basic information is supplied in the first pages of the site but if you want more information then for legal reasons you have to view and agree to a disclaimer.

I have used the script to facilitate this. ie. When the user clicks a link to view the extra information they are sent to “disclaimer.html” here they check the agree button and then hit submit which refreshes the page and they are magically transported to the “extra_info.html” page. This is working fine using the script as available on the link above. From then on in that session they can continue to view the information on “extra_info.html” without having to agree again because even though all the links to the extra info all point to “disclaimer.html” they are immediately redirected to “extra_info.html” until the cookie expires.

I have set the cookie to expire after 1 day, as for legal reasons they need to re-agree next time they visit the site.

My problem is that if they bookmark the “extra_info.html” page and return after a week they can view the info again without having to view the disclaimer. Or if google trawls the page and gives a direct link to that page, once again, it can be viewed without viewing the disclaimer.

Can anyone help me with a bit of code that I can put in the “extra_info.html” page that will check for the cookie and if it’s not there send them to the “disclaimer.html” page to set one?
//End extra explanation

Thanks!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @muddie 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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