create 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: php sessions
<?php
session_start();
$_SESSION['item_name'] = 'value';
$_SESSION['item_name'] = 0;
$_SESSION['item_name'] = 0.0;
$value = $_SESSION['item_name'];
?>
Example 3: destroy session php
<?php
session_start();
session_destroy();
unset($_SESSION['username']);
?>
Example 4: 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 5: create session in php
<?php
session_start();
$_SESSION["color"]= "blue";
$_SESSION["animal"]= "dog";
echo "The session variable are set up.";
?>
Example 6: php session variables
<?php
session_start();
$_SESSION['var'];
?>