Sessions
Last updated
What is Sessions?
Sessions provide a way to preserve certain data across subsequent accesses. Unlike a cookie, the information is not stored on the user's computer but on the server. This is particularly useful when you want to store information related to a specific user's session on your platform, like user login status or user preferences. When a session is started in PHP, a unique session ID is generated for the user. This ID is then passed and tracked through a cookie in the user's browser. To start a session, you would use the PHP function session_start(). To save a value in a session, you'd use the $_SESSION superglobal array. For example, $_SESSION['username'] = 'John'; assigns 'John' to the session variable 'username'.
Free resources to learn Sessions
- Official docsSessions
More in stage 10: State Management
Sessions: common questions
Can I learn Sessions 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 Sessions 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 Sessions tutorial for beginners?
It is lesson 58 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.