Sessions in PHP. An Example.
Lessons:
- sessions in PHP
- styles using div and span
- Reading a POST'd form
- php if with different blocks of HTML outputted
<html>
<html>
<head>
<meta description="Different cases cool differently. Check out these graphs of temperature over time">
<meta keywords="1u, case, cooling, tyan, supermicro, fans, cpu, mbmon, temperature">
<link rel="stylesheet" type="text/css" href="crazy-monkey.css" />
<title>Sessions in PHP - HOW-TO by Rudy</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#222222" vlink="#222222" alink="#222222" onload="checkForm();">
<a name="pagetop"></a>
<table bgcolor="#FFFFFF" border="0" width="100%" cellspacing="0" cellpadding="2">
<tr bgcolor="#FFCC00">
<td align="left">
MonkeyBrains.net/~rudy/example </td>
<td align="right"><b>
<a href="./" target="_top">Random examples</a></b></td>
</table>
<!-- a style defined in the head -->
<style>
.WorldOfPain {
background: #323;
color: #bf2;
text-align: center;
border: 3px dotted #515;
margin: 0;
padding: 4px;
}
</style>
<body>
<div class="WorldOfPain">Sessions in PHP. An Example.</div>
Lessons:
<ul>
<li>sessions in PHP
<li>styles using div and span
<li>Reading a POST'd form
<li>php <b>if</b> with different blocks of HTML outputted
</ul>
<?php
session_start(); // initialize the session. If you forget this, you will be screwed.
$error_style = '<span style="color: red; background: #fcc; border: 2px solid #f00">';
$error_style_end = '</span>';
if ($_POST['kraftwork'] === 'band') {
$mode = 'good';
} else {
if (isset($_POST['kraftwork'])) {
echo $error_style . "WRONG!" . $error_style_end;
$_SESSION['Your Wrong Answers'] .= $_POST['kraftwork'] . " ";
}
}
if ($mode != 'good') {
?>
<form method=POST>
What is kraftwork? <input type=text name=kraftwork size=15 value="<?php
echo $_POST['kraftwork'];
?>">
</form>
<?php
} else {
?>
You filled out the form correctly!
<p>
<?php
if (isset($_SESSION['Your Wrong Answers'])) {
echo $error_style;
echo "<b>Your wrong ansers were: " . $_SESSION['Your Wrong Answers'] . "</b><br>\n";
echo $error_style_end;
unset($_SESSION['Your Wrong Answers']);
}
}
?>
<p>
<hr name=>