PHP Session

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code
  4. Download Code

Code


To copy code: Click View Source “View Source” on the right of this code snippet.

Background and Explanation of the code

Session is used to store user’s data on the server side temporarily till the user left the site.All dynamic websites need this feature as web page output will be different for different users.

The function session_start() must be contained at the very start of the php page that is handling Sessions.With that you can store a session variable in one page and retrieve it on another page.session_destroy().The isset() function checks for if a session variable is exists and output can be altered on this basis.

Output: