Session in PHP – Session start destroy

What is Session in php ?
A session is a way to store information (variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer.

  • php Session is way to store information and this information will be available to all pages in one application. But when close browser the session information will destroy.
  • How to create session?
  • For maintaing session firstly call session_start() function. Because session_start() start session. Then create session variable like
  • $_SESSION[‘username’]=’shishir012010′;
  • here $_SESSION[‘username’] is a session variable and shishir012010 is information that store in $_SESSION[‘username’] variable.

Basic PHP Syntax
Example 1:- To create session



Example 2:- To access session

echo $_SESSION['username'];

Example 3:- To delete session


Note- The unset function is use delete one session variable
Example 4:- To delete all session variable


Note:- session_destroy() function delete all session variable.

session_id() function returns the session id for the current session.

Example 6:-

echo session_id();

Note:- we use session_id() for maintaining shopping cart.

Session variables solve this problem by storing user information to be used across multiple pagesBy default, session variables last until the user closes the browser.Session variables hold information about one single user, and are available to all pages in one application.


Admin has written 171 articles

Leave a Reply