Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Cookies.docx59.2 KB Cookies - Solution.docx
59.5 KB
Quick reference
Cookies
Cookies are small files that are placed on a website visitor's computer.
When to use
Cookies are useful tools to track website visitors.
Instructions
To work with Cookies, use the $_COOKIE superglobal.
To set a cookie:
setcookie(name, value, expire, path, domain, secure, httponly);
Place that code above the very top <html> tag of a web page.
To set the time for the expire section (in seconds):
time() + (86400 * 30)
To retrive a cookie:
echo $_COOKIE[$cookie_name];
To check to see if a Cookie has been set:
isset($_COOKIE[$cookie_name]);
Hints & tips
- setcookie(name, value, expire, path, domain, secure, httponly);
- Cookie expiration is measured in seconds
- to retrieve a cookie: echo $_COOKIE[$cookie_name];
- To check a cookie: isset($_COOKIE[$cookie_name]);
- time() + (86400 * 30)
Lesson notes are only available for subscribers.