PDA

View Full Version : Are cookies enabled?


flash
10-30-2002, 11:29 AM
Hey.

I need to some how detect if a user has cookies enabled on their browser or not. If so, then they can view the current page. If not then they are redirected to another page.

Can anyone help me with this?

Thanks in advance. :thumbsup:

Flash

flash
10-30-2002, 12:36 PM
I managed to do it myself now.

This is how to do it.

This script checks to see if JavaScript and Cookies are enabled.




<SCRIPT language=javascript><!--
var cookieName = 'test4Cookie' + (new Date().getTime());
document.cookie = cookieName + '=cookieValue';
var cookiesEnabled = document.cookie.indexOf(cookieName) != -1;
document.write("<p><font color=blue>You have ");
if (cookiesEnabled)
{
document.write(' <b>cookies enabled<\/b>. Please wait...<\/font><p>');
<!--

var n=navigator.appName
var ns=(n=="Netscape")
var ie=(n=="Microsoft Internet Explorer")
if (ns)
location="cookie.asp"
else if (ie)
location="cookie.asp"

//-->
}
else
{
document.write('you <font color=red><b>do not<\/b> have cookies enabled.<\/font><\/font><p>');
}

// --></SCRIPT>
<NOSCRIPT>
<P><font color="black">To view this page you need to have Cookies enabled.<p>

We can only check to see if you have cookies enabled if you have JavaScript enabled!<p>

</NOSCRIPT>