Chapter 12. Cookies

I l @ ve RuBoard

Cookies are one of the lesser understood and most maligned tools for today's World Wide Web. While many users have concerns about the security issues cookies are rumored to create, few people realize what benefits cookies offer to the user .

Prior to the existence of cookies, traversing through a Web site was a trip without a history. Although your browser tracks the pages you visit, allowing you to use the back button to return to previously visited pages and indicating visited links in a different color , the server keeps no record of who has seen what. All of this is still true for sites that do not use cookies, as well as for users who have disabled cookies in their Web browsers (Figure 12.1).

Figure 12.1. In Netscape Navigator, you can set your cookie permissions through Edit > Preferences > Advanced. In Internet Explorer 5.0 (for Macintosh) you would go through Edit > Preferences > Cookies, although different versions of the browsers are organized differently especially on Windows compared to Macintosh.

graphics/12fig01.jpg

Why is that a problem? Without the server being able to track a user, there can be no shopping carts for you to make purchases online. If cookies didn't exist or if they are disabled in your Web browser, people would not be able to use Hotmail, which requires user registration.

Cookies are a way for a server to store information about the user (on the user's machine) so that the server can remember the user over the course of the visit or through several visits . Think of a cookie like a name tag: you tell the server your name and it gives you a name tag. Then it can know who you are by referring back to the name tag.

This brings me to another point about the security issues involved with cookies. Cookies have gotten a bad rap because users believe that cookies allow a server to know too much about them. However, a cookie can only be used to store information that you give it, so it's as secure as you want it to be.

PHP has very good support for cookies. In this chapter you will learn how to set a cookie, retrieve information from a cookie, and then delete the cookie. You will also see some of the optional parameters you can use to apply limits to a cookie's existence.

I l @ ve RuBoard


PHP for the World Wide Web (Visual QuickStart Guide)
PHP for the World Wide Web (Visual QuickStart Guide)
ISBN: 0201727870
EAN: 2147483647
Year: 2001
Pages: 116
Authors: Larry Ullman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net