<?php // RAY_session_test.php
error_reporting(E_ALL);
// MAN PAGE HERE: http://us.php.net/manual/en/function.session-start.php
// START THE SESSION (DO THIS FIRST IN EVERY PHP SCRIPT ON EVERY PAGE)
session_start();
// SEE IF THE SUBMIT BUTTON WAS CLICKED
if (isset($_POST['fred']))
{
// SEE IF THE CHEESE VARIABLE IS SET IN THE SESSION ARRAY
if(!isset($_SESSION['cheese']))
{
// IF CHEESE IS NOT SET, SET IT TO ONE
$_SESSION['cheese'] = 1;
} else {
// IF CHEESE IS SET, ADD ONE TO IT
$_SESSION['cheese']++;
}
}
// END OF SCRIPT - SUPPRESS NOTICES IN THE HTML PART
error_reporting(E_ALL ^ E_NOTICE);
?>
<html><head><title>Session Test</title></head>
<body>
Currently, $_SESSION["cheese"] contains: <?php echo $_SESSION['cheese']; ?> <br/>
<form method="post">
<input type="submit" value="click" name="fred">
</form>
</body>
</html>
|