Session Create, View and Delete in PHP

 <?php

session_start();

// Below session id is "favcolor" and value is "orange"
$_SESSION["favcolor"] = "orange";

echo "Session Variable is set.";


?>


Session View File(Page)
<?php

session_start();

print_r($_SESSION);
echo "<br>";
echo "Favourite Color : " . $_SESSION["favcolor"]. "<br>";
?>
<html>
    <body>
        <?php
            if(isset($_SESSION["favcolor"]))
            {
                echo "Favourite Color : " . $_SESSION["favcolor"];
            }
            else
            {
                echo "Error! Session variable is Not Set.";
            }
        ?>
    </body>
</html>


Session delete File(Page)
<?php

session_start();

// session is not destroyed directly. First we have to unset session then only we can
// destroy session as shown below. Using session_unset(), all the session id will be deleted.
session_unset();

session_destroy();

echo "Session is destroyed!";

?>





Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions