How the session_start() works in php? When we write session_start() at top of the file, how the things are working in background.If anyone can explain.
CodePudding user response:
Session in PHP is just a variable that stores value in it. the session_start() is used to tell that we are using session variable in this code and that this function is mainly come at first whenever we want to use session and then when we want to remove value from it we could simply use session_destroy() function to remove the value from that variable Moreover, Session is mostly used when performing login. the username could be store in the variable that is declare as a session variable
session_start();
$_SESSION['username'] = 'John';
unset($_SESSION['username']);
echo $_SESSION['username'];
echo '/';
session_destroy();
$username = 'James';
if(isset($_SESSION['username'])){
echo 'Session is set';
}else{
echo 'Session not Exist';
}
?>```