最近一直在用php+dbfile开发blog,开发过程中学到了不少东西,于是就试着写了一个小留言本。
这个留言本采用php+dbfile,不需要使用数据库,可以放在blog中使用,比如http://www.customyze.com,这个blog中的Tag Board就是这个留言本。
整个留言本需要四个文件,分别是:board.php、index.php、config.php、admin.php。
board.php用来存储数据,可以先在里面添加了一条留言纪录。 代码拷贝框
<?php $Board=array( array(1081410332,'测试','测试留言本','http://www.piscdong.com') ); ?>
[Ctrl+A 全部选择 然后拷贝]
index.php是留言显示和提交页面。 代码拷贝框
<?php require_once('board.php'); function htmlencode($content){ $content=htmlspecialchars($content); $content=preg_replace("/\r/i","
",$content); return $content; } if($HTTP_SERVER_VARS['REQUEST_METHOD']=='POST'){ $configpath_parts1 = pathinfo($SCRIPT_FILENAME); $time=time(); $name=$HTTP_POST_VARS['name']; $url=(preg_match("/^[\\w-]+(\\.[\\w-]+)@[\\w-]+(\\.[\\w-]+)+$/i",$HTTP_POST_VARS['url'])
$HTTP_POST_VARS['url']=='')?$HTTP_POST_VARS['url']:'http://'.htmlspecialchars(preg_replace("/https?\:\/\//i",'',$HTTP_POST_VARS['url']),ENT_QUOTES); $info=htmlencode($HTTP_POST_VARS['info']); if($name!='' && $info!=''){ $Board[]=array($time,$name,$info,$url); } for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]="\tarray(".$bd[0].",'".$bd[1]."','".$bd[2]."','".$bd[3]."')"; next($Board); } $content="<?php\n\$Board=array(\n".join($s,",\n")."\n);\n?>"; $filename=$configpath_parts1['dirname'].'/'.'board.php'; if(is_writable($filename)
!file_exists($filename)){ if(!$handle=fopen($filename,'w')){ return false; } if(!fwrite($handle,$content)){ return false; } fclose($handle); }else{ return false; } header('Location:.'); }else{ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">