Baking Cookies 101
In English: [Tutorial] Cookies
I'm Comkid as you may know, anyway today I'm going to write a tutorial on Cookies. Anyway, let us begin.
Cookies have many uses, like storing information, storing items added to carts, staying logged in on a forum (like this one) and so on.
All cookies have a name, a value and an expiration date. These are the first three parameters of the setcookie function.
Example, Name - user, Value - rand & Expiration - 2 minutes from now:
<?php
setcookie('user', 'rand', time() + 120);
?>Accessing cookies are simple, all you need to know is the name of the cookie.
Example (Corresponds with first example):
<?php $cookie = $_COOKIE['user']; echo $cookie; ?>
This will now output:
rand
Finally, we must learn how to delete cookies before their expiration date. This is fairly simple just requiring the name of the cookie.
Example (Corresponds with first example):
<?php
setcookie('user', '', time() - 3600);
?>This makes the cookie 'user' expire an hour ago, which the browser will automatically delete.
Watch out for more of my tutorials
Thanks,
Comkid
If you liked this tutorial: Check out my new tutorial which is still Work-in-Progress: [ Linkie ]






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None





















Help