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.





PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net