You are here: Re: "Please enable your cookies" « All PHP « IT news, forums, messages
Re: "Please enable your cookies"

Posted by Jeff North on 02/02/06 09:15

On 1 Feb 2006 01:00:04 -0800, in alt.php "Mike"
<mike@mjfcadsolutions.co.uk>
<1138784404.505078.228370@g43g2000cwa.googlegroups.com> wrote:

>| Hi,
>|
>| I'm developing a site that requires cookies to pass data from page to
>| page, mainly to check that a user is logged in, store a username etc.
>|
>| What I need to do is before a user logs in, check that the browser has
>| cookies enabled, and if not display a "Please enable you cookies"
>| message before they try and login.

Here are the scripts to read and write cookies(watch out for the line
warps with the newsreader).
------------------------------------------------
<script type="text/javascript">
function SetCookie (name, value)
{
//-- expires in 1 day time ---
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

document.cookie = name + "=" + escape (value) + "; expires=" +
exp.toGMTString();
}
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}

// "Internal" function to return the decoded value of a cookie
function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

//--- set then retrieve value
SetCookie("nectar","testCookie");
var Cookies = GetCookie("nectar");
if( Cookies == null )
\\--- cookies not set so do something

</script>
----------------------------------

As another poster pointed out, javascript could be disabled as well.
You can place a <noscript> tag to alert the user that both cookies and
javascripting needs to be enabled.

<noscript>
<P>your message here</P>
</noscript>
---------------------------------------------------------------
jnorthau@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация