PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.00

What Is a Cookie?

This section describes what is a cookie - a piece of information sent by a Web server to a browser. The server expects the browser to send all cookies back to the server.

What Is a Cookie? A cookie is a piece of information sent by a Web server to a Web browser, saved by the browser, and sent back to the server later. Cookies are transmitted inside the HTTP header.

Cookies move from server to browser and back to server as shown in the following diagram:

Web         Web         Local       Web           Web
Server      Browser     System      Browser       Server

Send        Receive     Save        Send back     Receive
cookies --> cookies --> cookies --> cookies   --> cookies

As you can see from the diagram, cookies are actually saved by the local system in memory or on the hard disk of Web browser user's machines. Many users are concerned about this. But I think it is pretty safe to allow your browser to save cookies.

If you are really concerned, you can change your browser's settings to reject cookies. But this may cause many Web based applications fail to run on your browser.

Cookies are mainly used to pass information from one PHP script to the next script.

Last update: 2005.

Sections in This Chapter

What Is a Cookie?

Sending and Receiving Cookies

Sending and Receiving Cookies - Example

ob_start() - Output Buffering Function

Persistent Cookies Saved on Hard Disk

Other Cookie Properties - Domain and Path

Dr. Herong Yang, updated in 2009
What Is a Cookie?