Bake Your First PHP Cookie

 

Cookies are small pieces of information that are stored in your web browser. They typically contain data that is used to identify you when you look at a website so that site can be customized for each visitor.

The following script will set a cookie with the value of an email addess. It will also have an expire date / time.

The "echo" part of the script simply displays the cookie which we have set.

 

Script Source

 

<?php
setcookie("email", "youremail@youremail.co.uk", time() + 3600);
echo "<PRE>";
print_r($_COOKIE);
echo "<PRE>";
?>

 

Please let me know if this script was helpful to you.