Simpel session
Der er fejl i linie 13-14 på begge. Links kan findes her: http://www.korczynski.wep.dk/listing16.4.php og http://www.korczynski.wep.dk/listing16.5.phpHer er scriptne:
<?php
session_start();
?>
<html>
<head>
<title>Listing 16.4 Storing an array with a session</title>
</head>
<body>
<h1>Product Choice Page</h1>
<?php
if (isset($_POST[form_products])) {
if (!empty($_SESSION[products])) {
$products = array_unique(
array_merge(unserialize($_SESSION[products]), $_POST[form_products]));
}
$_SESSION[products] = serialize($products);
print "<p>Your products have been registered!</p>";
}
?>
<form method="POST" action="<?php $_SERVER[PHP_SELF] ?>">
<P>Select some products:<br>
<select name="form_products[]" multiple size=3>
<option>Sonic Screwdriver</option>
<option>Hal 2000</option>
<option>Tardis</option>
<option>ORAC</option>
<option>Transporter bracelet</option>
</select>
<br><br>
<input type="submit" value="choose">
</form>
<br><br>
<a href="listing16.5.php">content page</a>
</body>
</html>
<?php
session_start();
?>
<html>
<head>
<title>Listing 16.5 Accessing session variables</title>
</head>
<body>
<h1> Content Page</h1>
<?php
if (isset($_SESSION[products])) {
print "<b>Your cart:</b><ol>\n";
foreach (unserialize($_SESSION[products]) as $p) {
print "<li>$p";
}
print "</ol>";
}
?>
<a href="listing16.4.php">Back to product choice page</a>
</body>
</html>
