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!
Quote Reply
Re: [Andy] Cool "cookie check" routine.... In reply to
Code:
<script type="text/javascript">
<!--
if (navigator.cookieEnabled == 0)
alert("Cookies are disabled!");
-->
</script>
Quote Reply
Re: [Hargreaves] Cool "cookie check" routine.... In reply to
In Reply To:
Code:
<script type="text/javascript">
<!--
if (navigator.cookieEnabled == 0)
alert("Cookies are disabled!");
-->
</script>
I like mine better ;) (at least for what I've been doing with it Wink)

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!
Quote Reply
Re: [Andy] Cool "cookie check" routine.... In reply to
FWIW I couldn't get either example to work with IE6 SP2
Quote Reply
Re: [Hargreaves] Cool "cookie check" routine.... In reply to
You might also want to check to see if they have Javascript enabled Wink

This seems close to what you have plus the javascript check :

http://www.4guysfromrolla.com/webtech/082400-1.shtml

I know that you can do a server side check but that usually means you need to reload the page afterwards which is not great !

Hope this helps,

John
Significant Media
Quote Reply
Re: [Jag] Cool "cookie check" routine.... In reply to
You're right. To be honest it's too much effort.

I'd just put a message on the login page telling people that they need cookies enabled to login. People who have cookies disabled have generally manually disabled them so they don't need to be told they are disabled.
Quote Reply
Re: [Hargreaves] Cool "cookie check" routine.... In reply to
True sometimes it goes into overkill...

But we do all love holding our users hands to make the journey as painless as possible Wink

Take care,

John
Significant Media
Post deleted by Clint In reply to