Session related interview Questions

Ques:- What is session?
Ans:- A session is a way to store information (in variables) to be used across multiple pages.
sessions are stored on the server.

Ques:- How to create a session?
Ans:- We can create session through session_start() function

Ques:- How to set a value in session?
Ans:- We set the value like this $_SESSION[$name]=$value;
Example:-

<?php
$_SESSION['username']='John';
?>

Ques:- How to remove data from session?
Ans:- We can remove data through unset function.
Example:-

<?php
unset($_SESSION['username']);
?>

Ques:- How to get the value of current session id?
Ans:- session_id() returns the session id for the current session.
Example:-

<?php
session_id();
?>

Ques:- How to change session id on the page?
Ans:- We can change session id through session_regenerate_id(true) function.
Example:-

<?php
session_regenerate_id(true);
?>

Ques:- How to destroy all session data?
Ans:- We can destroy all session data through session_destroy(void) or session_unset(void); function.
Example:-

<?php
session_destroy();
or 
session_unset();
?>

Ques:- What is the default session time in php?
Ans:- The default session time in php is until closing of browser.