Tedd's Session "Ice Cream Flavors" - 1
This will add to a variable count and show the value in a session.
session count = 1session_id() = 6078965a82cf9cdb6c4e4795c57f2056
Array ( [icecream_flavor] => [cup_or_cone] => [location] => [count] => 0 )
This will add to a variable count and show the value in a session.
session count = 1session_id() = 6078965a82cf9cdb6c4e4795c57f2056
Array ( [icecream_flavor] => [cup_or_cone] => [location] => [count] => 0 )
<?php
session_name("tedd");
session_start();
include('../includes/header4.php');
error_reporting(E_ALL);
// look at the SESSION first -- if something is there, then use it -- else use ''
$icecream_flavor = isset($_SESSION['icecream_flavor']) ? $_SESSION['icecream_flavor'] : '';
$cup_or_cone = isset($_SESSION['cup_or_cone']) ? $_SESSION['cup_or_cone'] : '';
$location = isset($_SESSION['location']) ? $_SESSION['location'] : '';
$count = isset($_SESSION['count']) ? $_SESSION['count'] : 0;
// look at the POST second -- if something is there, then use it -- else use the session value.
$icecream_flavor = isset($_POST['icecream_flavor']) ? $_POST['icecream_flavor'] : $icecream_flavor;
$cup_or_cone = isset($_POST['cup_or_cone']) ? $_POST['cup_or_cone'] : $cup_or_cone;
$location = isset($_POST['location']) ? $_POST['location'] : $location;
$count = isset($_POST['count']) ? $_POST['count'] : $count;
// store any changes in the SESSION
$a = array();
$a['icecream_flavor'] = $icecream_flavor;
$a['cup_or_cone'] = $cup_or_cone;
$a['location'] = $location;
$a['count'] = $count++;
$_SESSION = $a;
?>
<h1>Tedd's Session "Ice Cream Flavors" - 1</h1>
<form action="session-test1.php" method="POST">
<label for="icecream_flavor">Icecream Flavor</label>
<input type="text" size="36" id="icecream_flavor" name="icecream_flavor"
value="<?php echo($icecream_flavor); ?>">
<br><br>
<label for="cup_or_cone">Cup vs. Cone</label>
<input type="text" size="36" id="cup_or_cone" name="cup_or_cone" value="<?php echo($cup_or_cone); ?>">
<br><br>
<label for="location">Location of the Shop</label>
<input type="text" size="36" id="location" name="location" value="<?php echo($location); ?>">
<input type="hidden" name="count" value="<?php echo($count); ?>">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<p>
This will add to a variable count and show the value in a session.
</p>
<?php
echo("session count = $count");
echo('<p>session_id() = ' . session_id() . '</p>');
?>
<pre>
<?php
print_r($_SESSION);
?>
</pre>
<form action="session-test2.php" method="post">
<input type="submit" value="Go to Page 2">
</form>
<?php
include('../includes/footer4.php');
?>
Last modified: November 01 2022
Line Count: 73