Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Cool "cookie check" routine....

Quote Reply
Cool "cookie check" routine....
Hi,

Just came up with a cool little "cookie check" bit of javascript :)

Code:
<script>
sessionCookieTest();

function testSessionCookie () {
document.cookie ="testSessionCookie=Enabled";
if (getCookieValue ("testSessionCookie")=="Enabled")
return true
else
return false;
}

function sessionCookieTest() {
if (testSessionCookie()) { } else { document.write('<h2>Cookie Warning!</h2><p>Your cookies seem to be disabled. <br> Logging in will not work until you enable cookies in your browser.') }
}


function getCookieValue (cookieName) {
var exp = new RegExp (escape(cookieName) + "=([^;]+)");
if (exp.test (document.cookie + ";")) {
exp.exec (document.cookie + ";");
return unescape(RegExp.$1);
}
else return false;
}
</script>

Simply place this code in login.html (anywhere you want, but recommended just above the <form ...> part of the template).

If someone doesn't have cookies enabled, then an error will be shown;

Quote:
<h2>Cookie Warning!</h2><p>Your cookies seem to be disabled. <br> Logging in will not work until you enable cookies in your browser.

Simple as that Cool

Hope that helps someone =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread Cool "cookie check" routine.... Andy 4424 Nov 3, 2005, 5:48 AM
Thread Re: [Andy] Cool "cookie check" routine....
Hargreaves 4325 Nov 3, 2005, 8:57 AM
Thread Re: [Hargreaves] Cool "cookie check" routine....
Andy 4355 Nov 3, 2005, 9:20 AM
Thread Re: [Andy] Cool "cookie check" routine....
Hargreaves 4339 Nov 3, 2005, 10:59 AM
Thread Re: [Hargreaves] Cool "cookie check" routine....
Jag 4340 Nov 3, 2005, 4:10 PM
Thread Re: [Jag] Cool "cookie check" routine....
Hargreaves 4324 Nov 3, 2005, 4:15 PM
Post Re: [Hargreaves] Cool "cookie check" routine....
Jag 4318 Nov 3, 2005, 4:18 PM
Post Post deleted by Clint
Clint 4295 Nov 6, 2005, 5:43 AM