O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 24

image

Cookies

A cookie is a small file kept on the client’s computer that can be used to store data relating to that user.

Creating cookies

To create a cookie the setcookie function is used. This function must be called before any output is sent to the browser. It has three mandatory parameters that contain the name, value and expiration date of the cookie.

setcookie("lastvisit", date("H:i:s"), time() + 60*60);

The value is here set with the date function, which returns a string formatted according to the specified format string. The expiration date is measured in seconds and is usually set relative to the current time in seconds retrieved ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required