Cookies
Last updated
What is Cookies?
Cookies are a crucial part of state management in PHP. They enable storage of data on the user's browser, which can then be sent back to the server with each subsequent request. This permits persistent data between different pages or visits. To set a cookie in PHP, you can use the setcookie() function. For example, setcookie("user", "John Doe", time() + (86400 * 30), "/"); will set a cookie named "user" with the value "John Doe", that will expire after 30 days. The cookie will be available across the entire website due to the path parameter set as /. To retrieve the value of the cookie, you can use the global $_COOKIE array: echo $_COOKIE["user"];.
Free resources to learn Cookies
- Official docsCookies
More in stage 10: State Management
Cookies: common questions
Can I learn Cookies in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Cookies in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Cookies tutorial for beginners?
It is lesson 57 of 120 in the free PHP roadmap, in stage 10, State Management. If you are new to PHP, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.