Setting and Reading Cookies
Create cookies with setcookie and read them from _COOKIE.
What Are Cookies?
Cookies are small pieces of data stored in the browser. The server sends them via the Set-Cookie header; the browser sends them back on every subsequent request.
setcookie()
setcookie() must be called before any output. It adds a Set-Cookie header to the response.
<?php
setcookie("username", "alice", time() + 3600);All lessons in this course
- Starting and Using Sessions
- Session Security Best Practices
- Setting and Reading Cookies
- Cookie Security: HttpOnly and Secure Flags