Posted By

devquora on 07/08/18


Tagged

php sessions


Versions (?)

Working with Sessions in PHP


 / Published in: PHP
 

URL: https://www.onlineinterviewquestions.com/core-php-interview-questions/

As HTTP is state protocol.To maintain states on server and share data across multiple pages PHP session are used.PHP sessions are simple way to store data for individual users/client against a unique session ID.Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data,if session id is not present on server PHP creates a new session, and generate a new session ID.

  1. <?php
  2. //starting a session
  3. //Creating a session
  4. $_SESSION['user_info']=['user_id'=>1,'first_name'=>'php','last_name'=>'scots','status'=>'active'];
  5.  
  6. //checking session
  7. if(isset($_SESSION['user_info'])){
  8. echo "logged In";
  9. }
  10.  
  11. //un setting remove a value from session
  12. unset($_SESSION['user_info']['first_name']);
  13.  
  14. // destroying complete session
  15.  
  16. ?>

Report this snippet  

You need to login to post a comment.