Приглашаем посетить
Культурология (cult-lib.ru)

Creating a Cookie

Previous
Table of Contents
Next

Creating a Cookie

<?php
  setcookie('version', phpversion());
?>
Tried to send cookie.


To create a cookie, the PHP function setcookie() can be used. It expects the following parameters; however, only the first one is mandatory:

  1. The name of the cookie

  2. The value of the cookie

  3. The expiry date (in UNIX epoche format)

  4. The path on the web server from which the cookie may be accessed

  5. The domain from which the cookie may be accessed

  6. Whether the cookie may only be sent using secure (HTTP Secure [HTTPS]/Secure Sockets Layer [SSL]) connections

The preceding code sets a simple session cookie with the current PHP version as its value.

Figure 5.2 shows a cookie warning in the Firefox browser. You can clearly see the cookie name and script.

Figure 5.2. Firefox receives the cookie and asks the user what to do.

Creating a Cookie



Previous
Table of Contents
Next