index.php
[code]
<?php
//kijk of opslag.txt bestaat, zo nee maakt  hij het aan
if(!file_exists('opslag.txt')){
fopen('opslag.txt','w+');
$test='bestaatniet';
}else{
$array=file('opslag.txt');
$test="bestaat";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Mijn eerste gastenboek</title>
<link href="style.css" type="text/css" rel="stylesheet" />
<meta name="author" content="ndm" />
<meta name="copyright" content="copyright (c) by nico de mooij" />
</head>
<body>
<form name="gastenboekform" action="index.php" method="post">

<fieldset class="inputgastenboek">
<table border="0"><tr><td>

<table border="0">
<tr><td>Naam: </td><td><input type="text" name="naam" /></td></tr>

<?php
// check of iemand een naam heeft ingevut
if(isset($_POST['try']) && $_POST['naam']==""){
echo '<tr><td colspan="2"><span class="error">U heeft geen naam ingevoerd</span></td></tr>';
$error='true';
}
?>

<tr><td>E-mailadres: </td><td><input type="text" name="email" /></td></tr> 

<?php
// check of iemand een emailadres heeft ingevut
if(isset($_POST['try']) && $_POST['email']==""){
echo '<tr><td colspan="2"><span class="error">U heeft geen e-mailadres ingevoerd</span></td></tr>';
$error='true';
}
?>

<tr><td>Bericht: </td><td></td></tr>
</table>
<textarea name="bericht" cols="50" rows="5"></textarea>
<table border="0">

<?php
// check of iemand een bericht heeft ingevut
if(isset($_POST['try']) && $_POST['bericht']==""){
echo '<tr><td colspan="2"><span class="error">U heeft geen bericht ingevoerd</span></td></tr>';
$error='true';
}
?>

<tr><td><input type="reset" name="reset" value="wis invoer" /></td><td><input type="submit" name="try" value="verzend" /></td></tr>
</table>
</td><td valign="top">
<fieldset class="smile">
<legend class="smile">smilies</legend>
<table border="0"><tr>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + ':) '"><img src="images/smile1.gif" alt="blij" border="0" height="15" width="15" /></a></td>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + ':D '"><img src="images/smile2.gif" alt="uberhappy" border="0" height="15" width="15" /></a></td>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + '}:-&lt; '"><img src="images/smile3.gif" alt="boze blik" border="0" height="15" width="15" /></a></td>
</tr><tr>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + ':S '"><img src="images/smile4.gif" alt="sorry" border="0" height="15" width="15" /></a></td>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + ':P '"><img src="images/smile5.gif" alt="lekker puh" border="0" height="15" width="15" /></a></td>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + ';) '"><img src="images/smile6.gif" alt="knipoog" border="0" height="15" width="15" /></a></td>
</tr><tr>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + '::) '"><img src="images/smile9.gif" alt="slik" border="0" height="15" width="15" /></a></td>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + ':( '"><img src="images/smile7.gif" alt="snif" border="0" height="15" width="15" /></a></td>
<td><a onclick="document.gastenboekform.bericht.value=document.gastenboekform.bericht.value + 'H) '"><img src="images/smile8.gif" alt="cool eh" border="0" height="15" width="15" /></a></td>
</tr></table>
</fieldset>
</td></tr></table>

<?php
// keuze tussen alles laten zien en de 5 recentste laten zien

if($_GET['show']=="vijf"){
echo '<a href="?show=nietvijf">laat alles zien</a>';
}else{
echo '<a href="?show=vijf">laat de 5 recentste zien</a>';
}
?>

</fieldset>
</form>

<?php
if(isset($_POST['try']) && $error!="true"){
// haalt extra gevegevens op
$time = date(H .':' . i .':' . s); //tijd van verzenden
$date = date(j .' '. M .' '. Y); //datum van verzenden
$ip = $_SERVER['REMOTE_ADDR']; //iemands ip-adres, kan je iemand op bannen
}
if(isset($_POST['try']) && $error!="true"){
// gaat in opslag.txt schrijven, opent hem
$file=fopen('opslag.txt','a'); //opent opslag.txt
$enter='
';

//enters uit het bericht halen
$bericht=str_replace($enter,'%',$_POST['bericht']);

//zet smilies erin
$bericht=str_replace('::)','<img src="images/smile9.gif" alt="slik" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace(':)','<img src="images/smile1.gif" alt="blij" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace(':D','<img src="images/smile2.gif" alt="uberhappy" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace('}:-<','<img src="images/smile3.gif" alt="boze blik" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace(':S','<img src="images/smile4.gif" alt="sorry" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace(':P','<img src="images/smile5.gif" alt="lekker puh" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace(';)','<img src="images/smile6.gif" alt="knipoog" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace(':(','<img src="images/smile7.gif" alt="snif" border="0" height="15" width="15" />',$bericht);
$bericht=str_replace('H)','<img src="images/smile8.gif" alt="cool eh" border="0" height="15" width="15" />',$bericht);

//start met schrijven
fwrite($file,$_POST['naam']);
fwrite($file,'&');
fwrite($file,$time);
fwrite($file,'&');
fwrite($file,$date);
fwrite($file,'&');
fwrite($file,$bericht);
fwrite($file,'&');
fwrite($file,$_POST['email']);
fwrite($file,'&');
fwrite($file,$ip);
fwrite($file,$enter);
//sluit opslag.txt weer af
fclose($file);
echo 'bedankt voor het schrijven in mijn gastenboek<br /><br />';
echo '<meta http-equiv="refresh" content="1;index.php" />';
}

// alle invoer laten zien
if($test='bestaat' && $_GET['show']=='vijf'){

//enters terugzetten
$i=0;
while($array[$i]){
$array[$i]=str_replace('%','<br />',$array[$i]);
$i++;
}

//opspiltsen
$j=0;
while($array[$j]){
$array[$j]=explode('&',$array[$j]);
$j++;
}
// bepaal het aantal keer dat er iets is ingevoerd, beginnend te tellen bij 0
$max=0;
while($array[$max]){
$max++;
}
$max--;

//geef alles weer
$l=0;
while($max>=0 && $l<5){
echo '<fieldset class="show">';
echo '<div class="show">';
echo '<table border="0" class="show" width="100%">';
echo '<tr>';
echo '<td align="left">';
echo $array[$max][0];
echo '</td>';
echo '<td align="right">';
echo $array[$max][1];
echo ' || ';
echo $array[$max][2];
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
echo '<div class="text">';
echo $array[$max][3];
echo '</div>';
echo '</fieldset>';
$l++;
$max--;
}


}elseif($test='bestaat'){
// enters teregzetten
$i=0;
while($array[$i]){
$array[$i]=str_replace('%','<br />',$array[$i]);
$i++;
}

//opsplitsen
$j=0;
while($array[$j]){
$array[$j]=explode('&',$array[$j]);
$j++;
}
// bepaal het aantal keer dat er iets is ingevoerd, beginnend te tellen bij 0
$max=0;
while($array[$max]){
$max++;
}
$max--;


//geef alles weer
while($max>=0){

echo '<fieldset class="show">';
echo '<div class="show">';
echo '<table border="0" class="show" width="100%">';
echo '<tr>';
echo '<td align="left">';
echo $array[$max][0];
echo '</td>';
echo '<td align="right">';
echo $array[$max][1];
echo ' || ';
echo $array[$max][2];
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
echo '<div class="text">';
echo $array[$max][3];
echo '</div>';
echo '</fieldset>';
$max--;
}

}
?>
</body>
</html>
[/code]


de stylesheet 'style.css'

[code]
body {
font-family: verdana, arial, times new roman;
font-size: 10pt;
}
fieldset {
border: 1px solid #00B900;
background: #EEEEEE;
padding: 7px;
}
fieldset.inputgastenboek {
width: 530px;
}
fieldset.error {
width: 170px;
}
fieldset.error2 {
width: 190px;
}
fieldset.login {
width: 250px;
background: #FFFFFF;
}
span.verplicht {
font-size: 8pt;
color: red;
}
fieldset.smile {
border: 1px solid #0000B9;
padding: 7px;
width: 60px;
margin: 15px;
}
legend.smile {
background: #0000B9;
color: #FFFFFF;
}
a:active, a:link, a:visited {
color: #0000B9;
text-decoration: none;
}
a:hover {
color: #009900;
text-decoration: underline;
}
fieldset.show {
margin: 2px;
margin-bottom: 10px;
width: 530px;
padding: 0px;
}
div.show {
margin: 0px;
padding: 3px;
background: #00B900;
}
div.text {
margin: 0px;
padding: 3px;
}
table.show {
padding: 0px;
margin: 0px;
}
span.error {
font-size: 8pt;
color: red;
font-family: verdana, arial, times new roman;
}

h1.login {
background: #EEEEEE;
color: #00B900;
margin: 3px;
margin-top: 0px;
padding: 3px;
padding-top: 0px;
border-top: 1px solid #0000B9;
border-bottom: 1px solid #0000B9;
}
[/code]