0PricingLogin
PHP Academy · Lesson

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

  1. Starting and Using Sessions
  2. Session Security Best Practices
  3. Setting and Reading Cookies
  4. Cookie Security: HttpOnly and Secure Flags
← Back to PHP Academy