Function

PHP session

session_start() function

session_start() function is used to start session

<?php
session_start();
?>

$_Session()

<?php
// Set session variables
$_SESSION["favfruite"] = "Apple";
$_SESSION["favgame"] = "chess";
echo "Session variables are set.";
?>

Example

<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<body>
<?php
// Set session variables
$_SESSION["favfruite"] = "Apple";
$_SESSION["favgame"] = "chess";
echo "Session variables are set.";
?>
</body>
</html>

Output

Session variables are set.

Destroying a PHP Session

lt;?php
// remove all session variables
session_unset();
// destroy the session
session_destroy();
?>