Deleting Cookies and Common Mistakes
Deleting cookies is very easy (don't you just love the complexity of this all?): to delete a cookie, you must set a cookie with an expiration date in the past, and give that cookie an empty value.
No, we're not going to teleport the cookie back in time, we'll simply make the computer think that is already expired.
For example, this is the code to delete the "username" cookie that we set earlier:
setcookie ("username", "", time()-99999);
Note: The -99999 value can be any negative value you wish.
Common Cookie Mistakes
The most common mistake that people make is setting a cookie after there has been output, which is usually signified by an error similar to the following:
Warning: Cannot modify header information - headers already sent by (output started at /home/yoursite/public_html/setcookie.php:2) in /home/yoursite/public_html/setcookie.php on line 4
Take note that cookies are sent along with the page headers and therefore must be sent before any of the page is output! "Output" includes text, images and whitespace. This does not apply to reading a cookie, a cookie can be read from any point in the page.
Conclusion
You should now be able to do basic tasks involving cookies as well as be aware of their limitations.
Have fun!