Chapter 12. Cookies

PHP has many functions and abilities for web sites. One of these capabilities is to create and use cookies. You may have heard of cookies while using your web browser. A cookie is a text file stored on the user’s machine. This text file has a data value, which stores some small amount of data. You just load this text file as a variable on pages that use the cookie, and that is your stored data! The text file is stored, in a hidden spot, by your web browser.

Basically, a cookie is a way for a site to save some data on your computer. This can be good and bad. For example, a lot of spyware sites use cookies to keep track of where you visit and use this data to sell ads to you. Also, make sure you don’t overdo it: A lot of people don’t like a lot of cookies because it can seem like you are storing data about them. On the other hand, using cookies allows you to choose and have those choices reflected on the site every time you use it.

This might seem vague, so let me give an example. Say you have a site where the user enters her name. This name might be reflected in many parts of the site, such as on the top of every page and in printable sections and documents. It is a little annoying to have to reenter her name every time the user enters the site, so adding cookies is a great way to make things a little easier. The Internet, as a whole, does not save data, so the developers of PHP came up with cookies.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.230