1<?php
2 session_start(); // start session
3 session_destroy(); // Delete whole session
4// OR
5unset($_SESSION['username']); // delete any specific session only
6?>
1<?php
2 // Start new or resume existing session.
3 session_start();
4
5 // Add values to the session.
6 $_SESSION['item_name'] = 'value'; // string
7 $_SESSION['item_name'] = 0; // int
8 $_SESSION['item_name'] = 0.0; // float
9
10 // Get session values.
11 $value = $_SESSION['item_name'];
12?>
1<?php
2 // Start the session
3 session_start();
4?>
5<!DOCTYPE html>
6<html>
7 <body>
8 <?php
9 // Set session variables
10 $_SESSION["color"]= "blue";
11 $_SESSION["animal"]= "dog";
12 echo "The session variable are set up.";
13 ?>
14 </body>
15</html>
1<?php
2 // Start the session
3 session_start();
4
5 // Set session variables
6 $_SESSION["color"]= "blue";
7 $_SESSION["animal"]= "dog";
8 echo "The session variable are set up.";
9?>
1<?php
2// start session before any HTML
3session_start();
4
5// create some variales in $_SESSION
6$_SESSION['name'] = 'myname';
7$_SESSION['surname'] = 'mysurname';
8$_SESSION['age'] = 24;
9?>
10
11<!DOCTYPE html>
12<html>
13 <head>
14 <meta charset="utf-8" />
15 <title>My page</title>
16 </head>
17 <body>
18 <p>
19 Hey <?php echo $_SESSION['name']; ?> !<br />
20 How are you today ?
21 </p>
22