Registration Cookies
I’m looking for some sample Java Script code for a registration cookie. Basically if they’ve registered and want access again to the site the cookie would allow them to bypass registration. Any links would be appreciated. Java Script is not exactly my specialty.
Thanks,
Mark Hensler posted this at 00:39 — 16th August 2000.
He has: 4,048 posts
Joined: Aug 2000
Are you sure you want to use JavaScript for this? I'd use a server side language.
Javascript isn't my thing either, but I have a book (which I haven't really read)...
Format:
cookieName=cookieValue; expires=expirationDateGMT; path=URLpath; domain=siteDomain
Save a cookie:
document.cookie="cookieName=cookieValue; expires=expirationDateGMT; path=URLpath; domain=siteDomain"
Get cookie:
document.cookie.split("=")[1] //returns cookieValue
After login, try:
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+6)
document.cookie="Registered=YES; expires="+expireDate.toGMTString()
For return visits, try something like this:
if (document.cookie.split("=")[1] == "YES") {
document.location="http://your.com"
}
Haven't tested this myself. This should create a cookie that expires in six months. When the person returns, they 'should' be forwarded to 'http://your.com'
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.