I had some trouble with this topic. The script in the apply your knowledge didnt seem to work on my WAMP im currently running PHP 5.3 i did alter the code to look like this:
on session.php
<?php
session_start();
$bgcolor = $_SESSION['bgcolor'];
if (isset($_GET['color']))
$color = $_GET['color'];
if (isset ($color)) {
switch ($color) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="#4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor="#FFE4C4";
break;
default:
$bgcolor = "white";
break;
} // end switch
}
if (empty ($bgcolor)){
$bgcolor = "white";
}
$_SESSION['bgcolor'] = $bgcolor;
?>
<html>
<head>
<title>Sessions</title>
</head>
<body bgcolor="<?php echo $bgcolor; ?>" />
<br />
<form method="get" action="session.php?<?php echo "PHPSESSID".session_id(); ?>" />
Select a background color
<br>
<input name='color' TYPE='radio' VALUE='Yellow'> Yellow
<br>
<input name='color' TYPE='radio' VALUE='Blue'> Blue
<br>
<input name='color' TYPE='radio' VALUE='Silver'> Silver
<br>
<input name='color' TYPE='radio' VALUE='Beige'> Beige
<br>
<br>
<input type="submit" value="Change Color" />
</form><br />
<br />
<a href="session.php?<?php echo "PHPSESSID".session_id(); ?>" > Refresh Page, Dont change background color</a><br />
<br />
<a href="session2.php?<?php echo "PHPSESSID".session_id(); ?>"> To Other Page </a>
</body>
</html>
This worked for me because session_register is deprecated.
and session2.php
<?php
session_start();
$bgcolor = $_SESSION['bgcolor'];
if (empty($bgcolor)) {
$bgcolor = "white";
}
?>
<html>
<head>
<title>Session Example</title>
</head>
<body bgcolor="<?php echo $bgcolor; ?>">
What color is my background?<br />
<br />
<a href="session.php?<?php echo "PHPSESSID".session_id(); ?>" /> Back to form </a>
</body>
</html>
Is this acceptable according to the course Mac?