_SESSION[] php code example
Example 1: php start a session
session_start();
if(!isset($_SESSION["started"]){
$_SESSION["started"] = true;
$_SESSION["attribute_1"] = $value_1;
...
$_SESSION["attribute_n"] = $value_n;
}
Example 2: session initialize php
session_start();
Example 3: php sessions
<?php
session_start();
$_SESSION['item_name'] = 'value';
$_SESSION['item_name'] = 0;
$_SESSION['item_name'] = 0.0;
$value = $_SESSION['item_name'];
?>
Example 4: destroy session php
<?php
session_start();
session_destroy();
unset($_SESSION['username']);
?>
Example 5: set php varibianle session
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
$_SESSION["color"]= "blue";
$_SESSION["animal"]= "dog";
echo "The session variable are set up.";
?>
</body>
</html>
Example 6: session php
<?php
session_start();
$_SESSION['name'] = 'myname';
$_SESSION['surname'] = 'mysurname';
$_SESSION['age'] = 24;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My page</title>
</head>
<body>
<p>
Hey <?php echo $_SESSION['name']; ?> !<br />
How are you today ?
</p>