<?php
/*
 * Simple guestbook. 
 * Output is in Norwegian, since it was used on a norwegian page.
 * The rest of the code is a bit mixed in regards to english/norwegian. 
 * Sorry, I'm just not used to coding for norwegian pages or something ;-) 
 * 
 * Written by Knut Auvor Grythe ( http://partyreg.net/~knuta/ )
 */

$file "messages.txt";

/* 
 * This one might cause problems inside framesets. In that case, just replace
 * $_SERVER['HTTP_REFERER'] with the page you want people sent to, written in 
 * double quotes. Like this: $referer = "guestbook.php";
 */
$referer $_SERVER['HTTP_REFERER'];

if(empty(
$_REQUEST["fra"]) || empty($_REQUEST["kommentar"])) {
    echo 
'Du m&aring; fylle ut b&aring;de navnet ditt og en kommentar. <a href="'.$referer.'">G&aring; tilbake</a>';
    exit;
}

$fra stripslashes(htmlentities($_REQUEST["fra"]));

if(!(empty(
$_REQUEST["hjemmeside"]) || $_REQUEST["hjemmeside"] == "http://" )) {
    
$fra '<a href="'.stripslashes(htmlentities($_REQUEST["hjemmeside"])).'">'.$fra.'</a>';
}

if(!empty(
$_REQUEST["epost"])) {
    
$epost stripslashes(htmlentities($_REQUEST["epost"]));
    
$fra $fra.' (<a href="mailto:'.$epost.'">'.$epost.'</a>)';
}

$kommentar stripslashes(nl2br(htmlentities($_REQUEST["kommentar"])));

$fd fopen ($file"r");
$content fread ($fdfilesize ($file));
fclose ($fd);

$content "<h2>$fra</h2>\n<p>\n$kommentar\n</p>\n$content";

$fd fopen($file"w");
fwrite($fd$content);
fclose($fd);
header("Location: $referer");
?>