What is session in php ?

In short session variables is used to stores the user information which can be used across one or multiple pages .

By default the session variables last since your are in the browser.

The session time deponds on the server configuration but by defult its 24 minutes or 1440 seconds.

The session generated for individuals user are unique  i.e. it is the unique identification of user and is known  by session id .

When the session starts  , either it retrieves its existing session id ( generally from session cookie ) or regenerate new session id .

It is defined as the super global variable $_SESSION .

The session by default  stored in the tmp and session.save_path variable influence the path of the session storage location which can be updated by the server administrator.

You must need tho start the session before session assigning the values in session , which can be done as ..

<?php 
  session_start() // Start the session

   $_SESSION[‘php’] =  ‘Working with the session variable  ‘ ;  //storing  the value in session

print_r($_SESSION);  // Print the values stored in session

?>  

Result :

Array([php] => Working with the session variable );

You can use session_destroy() function to destroy all the session  or

session_unset() to unset all the session values .

Similarly ,

 session_regenerate_id()   function to regenerate new session id .

 Please leave a comment for any query ..

Enjoy …………..

1 thought on “What is session in php ?

  1. Thanks for the useful information about PHP course, give more updates on PHP course, First time I visit your blog nice, I bookmark your blog here after a daily visit.

Leave a Reply to ajay ak Cancel reply

Your email address will not be published.Required fields are marked *