| php HTTP Cookies |
| Article Index |
|---|
| php HTTP Cookies |
| Page 2 |
Although quite useful as a protocol, HTTP is known in the computer science world as a "stateless" protocol. If that doesn't make sense to you, don't worry. Unlike your favorite programs that you run on your desktop, such as a word processor, PHP has no way of remembering a past request. The only information PHP has available to it when a script is executed is the information it was provided during the HTTP request. For example, what if you wanted to make a website that remembers the first name of every visitor and uses it to generate personalized content from your PHP scripts? How would you distinguish one visitor from another one in your PHP scripts? Cookies are used to solve this problem in a (fairly) eloquent way.
If you're still not sure how cookies work, consider the concept of valet parking. When you pull up, the staff gives you a ticket and goes and parks your car. After you have eaten your meal or have seen your show, you return to the staff and present them with your ticket and they get your car. Now, if you didn't have that ticket, how would the staff know which car was yours? Furthermore, if you don't have a ticket, how does the staff know you ever parked a car in the lot in the first place? This concept of a valet parking ticket is exactly how cookies work. When you visit a website, the server gives you a cookie that identifies you. Next time you visit the website (or even go to another page on that website) you give that cookie back to the server and it uses it to determine who you are.








