RE: [PHP] Re: Testing if cookies are enabled

From: Date: Tue, 22 Jun 2004 11:31:40 +0000
Subject: RE: [PHP] Re: Testing if cookies are enabled
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-188804@lists.php.net to get a copy of this message
Hi, You can check if browser cookies are enabled or not by using follow. given JavaScript functions. //****** jsfunc.js *******// function f_ReadCookie(cookieName) { if (cookieName == "" ) { return; } var theCookie=""+document.cookie+(("/") ? "; path=" + "/" : "") ; var ind=theCookie.indexOf(cookieName); if (ind==-1 || cookieName=="") return ""; var ind1=theCookie.indexOf(';',ind); if (ind1==-1) ind1=theCookie.length; return unescape(theCookie.substring(ind+cookieName.length+1,ind1)); /**** read cookie ****/ /***** Cookie Check function call ****/ f_WriteCookie("ckTmp","Y"); // write temp. cookie sVal = f_ReadCookie("ckTmp"); // read this value again if (sVal != "Y") { return false; } return true; } function f_WriteCookie(name, value) { if (name == "") { return false; } if (value != null) { var curCookie = name + "=" + escape(value) + (("/") ? "; path=" + "/" : "") //+ document.cookie = curCookie; } }// write cookie function f_CheckBrowserCookie() { // Cookie Check function call f_WriteCookie("ckTmp","Y"); // write temp. cookie sVal = f_ReadCookie("ckTmp"); // read this value again<br> if (sVal != "Y") { return false; } return true; } //****************** Use follow. given function in Onload of Body of HTML file of Login page ***************************// <SCRIPT language="JavaScript"> function CheckBrowserCookie() { if(!f_CheckBrowserCookie()) alert('Browser cookies are disabled.Please enable them.'); } </SCRIPT> // *********** in onload call it as below **********// <body bgcolor="#C7D1F1" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0" onLoad="CheckBrowserCookie();"> With these functions you will be able to check if the cookies are enabled or disabled. Regards, Umesh.

« previous php.general (#188804) next »