index.php
<?php
error_reporting (-1);
$templates = array('red', 'yellow', 'green');
if (isset( $_COOKIE ['template'])
&& in_array ( $_COOKIE ['template'], $templates )
) {
$style = $_COOKIE ['template'];
} else {
$key = array_rand ( $templates , 1);
$style = $templates [$key];
}
function createHTMLStyleLink($filename)
{
return sprintf('<link href="styles/%s.css"
media="screen"rel="stylesheet"
type="text/css">', $filename);
}
function createHTMLListBox ($name, $elements, $selected)
{
$listBox = sprintf ('<select name="%s">',
$name );
$option = '<option value="%s"%s>%s</option>';
foreach ($elements as $element) {
$x = ( $selected == $element )
? ' selected ="selected"'
: '';
$listBox .= sprintf ( $option ,
$element ,
$x,
$element );
}
$listBox .= '</select >';
return $listBox ;
}
$styleLink = createHTMLStyleLink ( $style );
$listBox = createHTMLListBox ('template',
$templates ,
$style );
require_once 'template.php';
?>
recepient.php
<?php
if (isset( $_POST ['ok'])) {
setcookie ('template',
$_POST ['template'],
time() + 60 * 60);
}
header ('HTTP/1.1 303 See Other');
$uri = sprintf ('http://%s/04/index.php',
$_SERVER ['SERVER_NAME']);
header ("Location : $uri");
?>
template.php
<!DOCTYPE html>
<html>
<head >
<meta charset ="utf -8">
<?php echo $styleLink; ?>
<title > </title >
</head >
<body >
<form action ="recepient.php" method ="post">
<label >
<?php echo $listBox; ?>
</label >
<input name="ok" type="submit" value =" ">
</form >
</body >
</html >
при открытии получаю вот такую "ошибку":
', $filename); } function createHTMLListBox ($name, $elements, $selected) { $listBox = sprintf (''; return $listBox ; } $styleLink = createHTMLStyleLink ( $style ); $listBox = createHTMLListBox ('template', $templates , $style ); require_once 'template.php'; ?>