Loading video...
Cookies
- A cookie is a piece of information set by an HTTP server and sent to a web client within an HTTP response for storage by the client.
- Cookies are associated with a particular website, and each time a client requests a page from a website for which it has received & stored a cookie, it includes the corresponding cookie’s data within its HTTP request.
- HTTP is a stateless protocol meaning that each HTTP transaction between a client & server has no ‘memory’ of any previous transactions.
- The purpose of cookies is to allow state, or knowledge of previous events, to be introduced into HTTP transactions.
- The way a web server sends a cookie to a client is via the
Set-Cookieheader of an HTTP response:HTTP/1.1 200 OK
Date: Wed, 3 Aug 2011 23:59:59 GMT
Content-Type: text/html
Set-Cookie: cookie=cookieValue
Host: www.educator.com - Cookie data is in the form of name-value pairs.
- Each time a client requests a page from a website for which it has a cookie, it sends the cookie’s
information back to the server using the
CookieHTTP request header:GET /index.html HTTP/1.1
Host: www.educator.com
Cookie: cookie=cookieValue setcookie()is a built-in PHP function that allows a script to send a cookie to a web client. It must be called before any of a script’s output is generated.- Cookies have several attributes that can be set which determine whether a client sends a particular cookie in
its request for a page from a particular website:
domain– specifies the domain which a cookie applies topath– specifies a particular path within a domain that the cookie applies toexpires– the data & time when a cookie is no longer valid
$_COOKIEis a superglobal associative array containing any cookie name/value pairs sent by a client in its request for a PHP script.- Additional Resources:
Cookies
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.
- Intro
- Lesson Overview
- What is a Cookie?
- HTTP - A Stateless Protocol
- Set - Cookie Header
- Cookie Header
- setcookie()
- Cookies Attributes
- Cookies Attributes Overview
- Common Cookies Attributes: Domain
- Common Cookies Attributes: Path
- Common Cookies Attributes: Expires
- Coding Example: Setting Cookie Attributes
- $_COOKIE Superglobal
- Security Implications
- Homework Challenge
- Homework Challenge (cont.)


































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview