| [main] [misc] [graphics] [page design] [site design] [xhtml] [css] [xml] [xsl] [schema] [javascript] [php] [mysql] | |
Note that all external links will open up in a separate window. This is a stripped down version of these pages for older browsers. These pages are really meant to be viewed in a standards compliant browser. |
Reading CookiesThese tutorials are about JavaScript and its use for client-side Web programming. Reading Cookies
When you read a cookie, which is to say, when you look at the contents of the
There are numerous way to search a cookie string for information. You can use the Here is an example of splitting the cookie into an array:
// create a temp array
tempArray = someStr.split(';');
// create an array of arrays
finalArray = new Array();
xyz = 0;
for (elName in tempArray) {
finalArray[xyz] = tempArray[elName].split('=');
xyz++;
}
// test for our desired value
for (elName in finalArray) {
if (finalArray[elName][0] == desired cookie) {
process cookie value finalArray[elName][1];
}
The advantage of doing it this two-step way is that some browsers include the cookie attributes as part of the returned cookies string, after the name value pair. This can mess up your cookie processing if you assume that there is just one cookie and therefore you only need to check for an equals sign. If you do this, then what you thought was your cookie value may actually be a string suffixed by the name of the next attribute, like "100;expires". There is of course, also the possibility that while you think there is only one cookie set that you can access, there may be multiple cookies. This would produce the same type of error, since they are strung together in a semi-colon delimited list.
Don't When reading cookies, you only have access to the name=value pairs. You do not have access to any of the other cookie properties that may be set for that cookie.
These pages can be found at:
[http://academ.hvcc.edu/~kantopet/]
|