Source code file: session.php


<?php
session_start
();
?>



<!DOCTYPE html>
<html>
<head>

<?php include 'css.htm';?>

</head>


<body>


<?php 

        $pageName 
= basename($_SERVER['PHP_SELF']); /* Returns The Current PHP File Name */ 
        
        
echo "<h3>&nbsp;" . $pageName . "</h3>  ";
        echo 
"&nbsp;<a href='../my-php/read_code.php?file=" . $pageName . "' target='_blank'>   View Code  </a>";
        

?>


<table background="images/bg.png" style="width:98%" style="height:640px">

        <tr>
                <td style="width:20%">
                    <br>Click on the links in the menu for more PHP examples.<br>


                            <?php include 'menu.php';?>

                </td>
                
                <td height="95%" bgcolor="white" style="vertical-align:top">
                
                    
                    <h2>PHP Server Session</h2><br><br>
                    A session is a way to store information (in variables) to be used across multiple pages.

Unlike a cookie, the information is not stored on the users computer.<br><br>
                    
                    
<?php
// session start, set variables, echo variables, unset session, kill session

echo "session start, set session variables, echo session variables, unset session variables, kill session<br><br>";
echo 
"session started<br>";

$_SESSION["firstName"] = "Jamie";

$_SESSION["userID"] = "jamieD";

$_SESSION["acl"] = 100 ;

echo 
"<br>session array is created, variables set<br>";
print_r($_SESSION);

// Echo session variables
echo "<br>session variables set<br>";
echo 
"session variable firstName is set to " . $_SESSION["firstName"] . ".<br>";
echo 
"session variable userID is set to " . $_SESSION["userID"] . ".<br>";
echo 
"session variable acl is set to " . $_SESSION["acl"] . ".<br>";

// remove all session variables
session_unset();
echo 
"<br>Session variable unset<br>";
echo 
"session variable firstName is set to " . $_SESSION["firstName"] . ".<br>";
echo 
"session variable userID is set to " . $_SESSION["userID"] . ".<br>";
echo 
"session variable acl is set to " . $_SESSION["acl"] . ".<br>";

print_r($_SESSION);

// destroy the session
session_destroy();
echo 
"<br><br>Session destroid<br>";
echo 
"session variable firstName is set to " . $_SESSION["firstName"] . ".<br>";
echo 
"session variable userID is set to " . $_SESSION["userID"] . ".<br>";
echo 
"session variable acl is set to " . $_SESSION["acl"] . ".<br>";

print_r($_SESSION);

?>
<p>
<br><br> Here is the php code I used to create a server session, load session variables, output session variables to the page, and kill the session. 
                    <br><br>
                    <img src="images/php_session.jpg" alt="php session."><br><br>

                    
                    
                    
                </td>
        </tr>  
</table>


</body>
</html>