- We cover in this artical these question.
- What is session. how to store data in session in php.
- how to Access data in session in php.
- how to check session varibale is set or not set in php.
- how to Destroy data in session in php.
What is session: A special type of variable.
whose value is maintained accross subsequent pages.This variable store data in session.sintex: $_SESSION['variable']
How to start session:
Before use session we need to start session .we can use this sintex for start session in php. session_start();how to store data in session in php:
// Starting session session_start(); // Storing session data $_SESSION["firstname"] = "rakesh";$_SESSION["lastname"] = "kumar";
These are the two session variable
$_SESSION["firstname"]
$_SESSION["lastname"]
how to Access data in session in php:
// Starting session session_start(); // Accessing session dataecho 'Hi, ' . $_SESSION["firstname"] . ' ' . $_SESSION["lastname"];
how to check session varibale is set in php:
if(isset($_SESSION["lastname"])){
return true;
}
how to Destroy data in session in php:
unset($_SESSION["lastname"]); // for unset session variablesession_destroy(); // for completely remove session
No comments:
Post a Comment