设为首页 加入收藏

TOP

php+dbfile开发小型留言本
2011-05-31 16:09:37 来源: 作者: 【 】 浏览:539次 评论:0
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">
您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇如何将gd编译进php for Linux. gd.. 下一篇PHP中创建并处理图象

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位