|
Develop your complete privacy policy using P3Pwriter. You can make changes for up to a year at no charge and we guarantee it will validate or you get your money back. Start here --> |
|
2.0 Cookie Methods
The following describes three methods of using cookies. The first is a client-side implementation and the last two are server-side cookies.
2.1 JavaScript Cookie Method
Create a cookie with the specified name and value.
| function SetCookie(sName, sValue){ |
| document.cookie = sName + "=" + escape(sValue) + "; |
| expires=Mon, 31 Dec 2010 23:59:59 UTC;"; |
| } |
| |
Retrieve the value of the cookie with the specified name.
| function GetCookie(sName){ |
| var docCookie = document.cookie |
| if(docCookie.length>0){ |
| var begin = docCookie.indexOf(sName+'=') |
| if(begin!=-1){ |
| end=docCookie.indexOf(';', begin) |
| if(end==-1)end=docCookie.length |
| return unescape(docCookie.substring(begin+sName.length+1, end)) |
| } |
| } |
| //a cookie with the requested name does not exist |
| return null |
| } |
2.2 PHP Cookie Method
int setcookie (string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
| Setting a Cookie: | setcookie ("TestCookie", $value,time()+3600); /* expire in 1 hour */ |
| Getting a Cookie: | $HTTP_COOKIE_VARS["TestCookie"]; |
2.3 ASP Cookie Method
| Setting a Cookie: | Response.Cookies("name") = value |
| | Response.Cookies("name").Expires = Date + 365 |
| Getting a Cookie: | value = Request.Cookies("name") |
|