Location: PHPKode > scripts > textGUESTBOOK > textGUESTBOOK/textGUESTBOOK.php
<?
// TextGUESTBOOK version 1.0, free for none commercial use
//
// Features:
//  0. no db required
//  1. spam control
//  2. secure admin
//  3. simple
//  4. auto archive

$mypwd="123";  				//so, contents is secure
$my_access_code="Nospam";        	//Prevent spam bot
$order=1;          			//try $order=0 :)
$maxmsgs=10;				//max message per page
$maxpage=18;				//max pages, old pages auto rename to old.date

//--------------------CSS style-------------------------//
$header='<!DOCTYPE html>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>textGUESTBOOK simple easy tiny guestbook by ppGATE.net</TITLE>
<META NAME="DESCRIPTION" CONTENT="textGUESTBOOK is tiny and simple, just one single file,tools,free,rich features,secure editing,auto archive,delete,speedy editor">
<META NAME="KEYWORDS" CONTENT="guestbook,simple guestbook,flat file,plain text,plaintext,ascii,green,small,tiny,easy,no setup,no config">
<LINK REL="SHORTCUT ICON" HREF="http://www.ppGATE.net/favicon.ico" type="image/x-icon">
<LINK REL="ICON" HREF="http://www.ppGATE.net/favicon.ico" type="image/x-icon">
<META NAME="AUTHOR" CONTENT="made by ppGATE">
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html;charset=UTF-8">
<STYLE TYPE="TEXT/CSS">
body{background:#F8F8F8;font-family:"LucidaGrande",Calibri,Arial;}
h1{display:block;padding-left:50px;background:url("textGUESTBOOK.png") no-repeat;}
a{color:#009AF8;text-decoration:none;}
a:hover{text-decoration:underline;}
p,li{color:#666;}
h1 small,div.box small{display:block;color:#999;font-size:14px;font-style:italic;font-weight:normal;}
h2{font-size:15px;margin:10px 0px 0px 2px;border-bottom:1px dashed #D7D7D7;}
h2 small{font-size:11px;}
#container{width:900px;margin:20px auto;min-height:600px;!important;height:auto;background:#ffffff;}
div.box{height:35px;padding:10px;padding-left:60px;margin-right:5px;}
#index{float:right;width:150px;margin:10px;background:#F8F8F8;padding:10px 10px 10px 30px;list-style-type:square;}
#edit{width:900px;margin:auto;text-align:right;}
#foot{width:900px;height:20px;margin:auto;border-top:1px solid #D7D7D7;text-align:center;}
#navP{width:900px;text-align:center;background:#eeeeee;}
#navP a{display:block;width:25px;height:25px;padding:0px;margin-right:5px;line-height:25px;border:1px solid #D7D7D7;float:left;}
#navP a:hover{background:#0000ff;border:1px solid #D7D7D7;color:#ffffff;text-decoration:none;}
#sign{width:900px;margin:20px auto;;min-height:120px;!important;border:1px solid #D7D7D7;background:#eeeeee;}
textarea{width:680px;min-height:500px;!important;height:auto;}
.text{width:800px;min-height:80px;!important;margin:auto;}
.c{background:#ffffff;font-weight:bolder;}
pre{width:700px;font-family:"LucidaGrande",Calibri,Arial;padding:5px;margin:0px 60px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;background:#eeeeee;}
</STYLE>
</HEAD><BODY onLoad="document.forms[0].elements[0].focus()"><DIV id="container">';

$footer='<DIV id="foot">
<SMALL>Powered by <a href=http://www.ppGATE.net/textGUESTBOOK/>textGUESTBOOK</a> 1.0.0 &copy; 2011 <a href=http://www.ppGate.net/>ppGATE.net</A></SMALL>
</DIV></BODY></HTML>';

$title .= "<h1> Guestbook </h1>";


////////////////////////////////////update below at your own risk :)//////////////////////////////////////////////////
$uri=$_SERVER['HTTP_URI'];
$ref=$_SERVER['HTTP_REFERER'];
$dir = dirname(__FILE__) . "/d" ;

$p = $_GET['p'];
$edit = $_GET['edit'];

if ( $edit != '' ) {
	$edit = "<h2>Password Required</h2><p><form method=post><input type=password name=pwd><br><input type=submit></form>";	
	$pwd=$_POST['pwd'];
	if ( $pwd == $mypwd ) {
		if ( !isset($p) || $p == '' )
			$p=0;
		else
			$p=preg_replace("/\#.*/",'',$p);

		$m=$_POST['m'];
		$submit=$_POST['submit'];
		if ( isset($m) ) {
			if ( preg_match("/delete/i",$submit) ) {
				unlink("$dir/$p");
				$ref=preg_replace("/\?.*/","",$ref);
				header("Location: $ref");		
			} else {
				file_put_contents("$dir/$p",$m);
				$ref=preg_replace("/edit=[^&]*/","",$ref);
				header("Location: $ref");		
			}
		} else {
			$m = file_get_contents("$dir/$p");
			$i=0;
			if ($dh= opendir($dir)) {
    				while (false !== ($file = readdir($dh))) {
					if ( preg_match("/old/",$file ) ) {
						$olds[$i]=$file;
						$i++;
					}
				}
				closedir($dh);
			}
			if ( $i > 0 ) {
				sort($olds);
				$old = "\n<ul id=\"index\">Old Messages";
				if ( $i > 23 )
					$olds = array_slice($olds,0,23);
				foreach ( $olds as $f )
					$old .= "<li><a href=?p=$f>$f</a></li>";
			}
			
			if ( $i > 23 )
				$old .= "<li> remove to get more </li>";
			$old .= "</ul>";
			if ( preg_match("/old/",$p) )
				$delete = "<input type=submit name=submit value=Delete>";
			$edit = "$old<h2>Editing page: $p</h2><p><form method=post><textarea name=m>$m</textarea><br><input type=submit name=submit value=Save>$delete<input type=hidden name=pwd value=\"$pwd\"></form></p>";
			echo $header.$title.$edit."</DIV>".$footer;
		}
		exit;
	} else {
		if ( isset($pwd) )
			$edit .= "wrong key";
	}
	echo $header.$title.$edit."</DIV>".$footer;
	exit;
}

$n=$_POST['n'];
$e=$_POST['e'];
$c=$_POST['c'];
$code=$_POST['code'];

if ( $c != '' && preg_match("/$my_access_code/i",$code) ) {
	$c = preg_replace("/</","&lt;",$c);
	$e = preg_replace("/</","&lt;",$e);
	$n = preg_replace("/</","&lt;",$n);

	$id=$_POST['id'];

    	$file="$dir/0";
	if ( $id >= $maxmsgs ) {
		$date=date("Yjdhi");
		if ( file_exists("$dir/$maxpage") )
			rename("$dir/$maxpage","$dir/old.$date");
		while($maxpage) {
			$maxpage--;
			$newpage=$maxpage+1;
			if ( file_exists("$dir/$maxpage") )
				rename("$dir/$maxpage","$dir/$newpage");
        	}
               	$fp=fopen("$dir/0","a+");
		fclose($fp);
		$id=0;
	}

	if ( !$id )
		$id=0;

	$date = date( "F j Y, h:i a");
	if ( $n == '' )
		$n = "Anonymous";

	if ( $e != "" )
		$m="<? \$id=$id; ?>\n<h2><a href=mailto:$e>$n</a> <small>$date</small></h2>\n    <p><pre>$c</pre></p>\n";
	else
		$m="<? \$id=$id; ?>\n<h2>$n <small>$date</small></h2>\n    <p><pre>$c</pre></p>\n";

	if ( $order == 1 ) {
		$o  = file_get_contents($file);
		$o  = preg_replace('/<\? \$id=\d*; \?>/i',"",$o);
		file_put_contents($file,"$m\n$o");
	} else {
		$fp = fopen($file,"a");
		fwrite ($fp, $m);
		fclose($fp);
	}	

	$ref=preg_replace("/p=[0-9]*/","",$ref);
	header("Location: $ref");

} else {
	$i=0;$j=1;
	while(1) {
		if ( file_exists("$dir/$j") )
			$j++;
		else
			break;
	}
	$navp = "\n<div id=navP>";
	while($i<$j){
		if ($i == $p )
			$navp .="<a class=c href=?p=$i>$i</a>";
        	else
                	$navp .="<a href=?p=$i>$i</a>";
        	$i++;
  	}
	$navp .= "<a style=\"width:80px\" href=#sign>Sign</a>";
	$navp .= "<a style=\"width:80px\" href=?p=$p&edit=edit>edit</a><div style=\"clear:both;\"></div></div>\n";


	if ( $p && file_exists("$dir/$p")){
		echo $header.$title.$navp;
        	include "$dir/$p";
  	}else{
        	if ( file_exists("$dir/0") ){
			echo $header.$title.$navp;
                	include "$dir/0";
                	$id++;
        	} else {
               		$fp=fopen("$dir/0","a+");
			$empty="<? \$id=0; ?>\n<h2>New guestbook</h2>\n    <p>Congratulation! Here's your brand new guestbook.</p><p>Default password is \"123\".</p>\n";
			$empty.="<p>By default, each page will hold <b>10</b> guest entries, and keep total of <b>18</b> pages visitable for public. That's 180 messsage total.</p>\n";
			$empty.="<p>All these numbers including the password and access code can be easily changed at the beginning of this script.</p>\n";
			$empty.="<p>Please sign my <a href=http://ppgate.net/textGUESTBOOK/>guestbook</a>.</p>\n";
			fwrite($fp,$empty);
                	fclose($fp);
			echo "<meta http-equiv=refresh content=\"2\"><body><h2>Please wait...<br>or check the permision of your data directory. (chmod 777 $dir)";
			exit;
        	}
  	}
}

$form = "</div><div id=sign><form method=post>
Name <input type=text name=n>&nbsp;
Email <input type=text name=e>&nbsp;
Access code <input type=text name=code>
<input type=submit name=submit><br>
Please enter <b>$my_access_code</b> into Access code above.
<textarea name=c class=text></textarea>";

echo $form."<input type=hidden name=id value=$id></form></div>".$footer;
?>
Return current item: textGUESTBOOK