15.1. Managing Sessions with Cookies

One way to identify users and to store data is to use cookies. For a long time cookies were the only solution for storing session data permanently, and they are still widely used today.

15.1.1. Cookie Fundamentals

HTTP is not a connection-oriented protocol, so cookies can be used to fake some sort of permanent interaction with the server. The idea of a cookie is to store information directly on the client. Whenever a site is called, the information in the appropriate cookie is sent to the server automatically. Keep in mind that the server does not look for the cookie—the information is sent to the server by the browser automatically. Let's look at a simple example:

 <?php setcookie ("YourName", "Hans-Jürgen ...

Get PHP and PostgreSQL: Advanced Web Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.