Session in PHP

Session in PHP

Session is used to set the value that you can see across several pages and not pass them back and forth,but you don't want them to be remembered beyond the users' visit.Just like some websites have a remember me checkbox.They store the login information to keep you logined on every page.If you don't check that box.they store the information temporarily.After you close the browser,the information is lost.

To create or start a session :


When you called that function,you set and get the superglobals variable $_SESSION.Session variables will persist until users close their browsers

    if (isset($_GET["name"])) {
        $_SESSION["name"] = $_GET["name"];
<p>Thanks <a href="test2.php">mesesage</a></p>  
<?php }    elseif (isset($_SESSION["name"])) {  
    echo "Hi {$_SESSION["name"]}";
} else {?>
<form action="test2.php" method="GET">  
    <input type="text" name="name">
    <input type="submit" value="submit">
<?php } ?>  

If you close the tab and reopen it.The message is strill there.

You can remove the session variable by using unset() function,this will remove any variable