当前位置:编程学习 > php >>

php+dbfile开发小型留言本

board.php用来存储数据,可以先在里面添加了一条留言纪录。
代码
<?php
$Board=array(
array(1081410332,'测试','测试留言本','http://www.piscdong.com')
);
?>
index.php是留言显示和提交页面。
代码
<?php
require_once('board.php');
function htmlencode($content){
$content=htmlspecialchars($content);
$content=preg_replace("//i","<br />",$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[]=" array(".$bd[0].",'".$bd[1]."','".$bd[2]."','".$bd[3]."')";
next($Board);
}
$content="<?php $Board=array( ".join($s,", ")." ); ?>";
$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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>留言本</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form method="post" name="form1" action="">
<table border="0" cellspacing="5" cellpadding="0" align="center">
补充:Php教程,Php应用 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,