php+dbfile开发小型留言本


Posted in PHP onOctober 09, 2006

最近一直在用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","<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[]="\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"> <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"> <tr> <td> <div style="overflow:auto;height:250px;border:1px dotted #999999;padding:5px;word-wrap:break-word;width:400px;"> <?php end($Board); for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]='<strong>'.($bd[3]!=''?'<a href="':'').(preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3])?'mailto:':'').$bd[3].(($bd[3]!='' && !preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3]))?'" target="_blank':'').($bd[3]!=''?'">':'').$bd[1].($bd[3]!=''?'</a>':'').':</strong> '.$bd[2].'<br/><em>-'.date("G:i, M j, Y",$bd[0]).'</em>'; prev($Board); } echo join($s,'<br/><br/>'); ?> </div> </td> </tr> <tr> <td align="center"> 名称:<input type="text" name="name"/> URL/Email:<input type="text" name="url"/><br/> <textarea name="info" cols="40" rows="8"></textarea><br/> <input type="submit" value="发布"/> </td> </tr> </table> </form> </body> </html> <?php } ?>
[Ctrl+A 全部选择 然后拷贝]

config.php中存放的是管理留言本的密码,把密码放在单独一个文件中方便修改。 代码拷贝框
<?php $password='123456'; ?>
[Ctrl+A 全部选择 然后拷贝]

admin.php是管理页面,功能很简单,只能删除留言。在删除时需要输入管理密码,管理密码存放在config.php中。 代码拷贝框
<?php require_once('board.php'); require_once('config.php'); if(isset($HTTP_POST_VARS['id']) && $HTTP_POST_VARS['id']!='' && addslashes($HTTP_POST_VARS['password'])==$password){ if(count($Board)>1){ unset($Board[intval($HTTP_POST_VARS['id'])]); 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?>"; $configpath_parts1 = pathinfo($SCRIPT_FILENAME); $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:admin.php'); }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> <table width="500" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999"> <?php for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]='<tr><td bgcolor="#'.($i%2!=0?'ececec':'ffffff').'"><strong>'.($bd[3]!=''?'<a href="':'').(preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3])?'mailto:':'').$bd[3].(($bd[3]!='' && !preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3]))?'" target="_blank':'').($bd[3]!=''?'">':'').$bd[1].($bd[3]!=''?'</a>':'').':</strong> '.$bd[2].'<br/><em>-'.date("G:i, M j, Y",$bd[0]).'</em></td>'.(count($Board)>1?'<td bgcolor="#'.($i%2!=0?'ececec':'ffffff').'" align="center"><form method="post" action=""><input type="submit" value="删除" /><input type="hidden" name="id" value="'.$i.'" /><input type="password" name="password" /></form></td>':'').'</tr>'; next($Board); } echo join($s,''); ?> </table> </body> </html> <?php } ?>
[Ctrl+A 全部选择 然后拷贝]

这个留言本还很简单,功能上还不健全,比如没有分页等,还可以继续完善。:-)

PHP 相关文章推荐
如何在PHP中进行身份认证
Oct 09 PHP
PHP 动态随机生成验证码类代码
Apr 09 PHP
PHP中PDO的错误处理
Sep 04 PHP
Array of country list in PHP with Zend Framework
Oct 17 PHP
PHP5权威编程阅读学习笔记 附电子书下载
Jul 05 PHP
关于php 接口问题(php接口主要也就是运用curl,curl函数)
Jul 01 PHP
PHP实现Soap通讯的方法
Nov 03 PHP
使用php的HTTP请求的库Requests实现美女图片墙
Feb 22 PHP
php实现zip文件解压操作
Nov 03 PHP
利用PHP绘图函数实现简单验证码功能的方法
Oct 18 PHP
PHP一致性hash分布式算法封装类定义与用法示例
Aug 04 PHP
PHP大文件及断点续传下载实现代码
Aug 18 PHP
用 php 编写的日历
Oct 09 #PHP
第十三节 对象串行化 [13]
Oct 09 #PHP
第七节 类的静态成员 [7]
Oct 09 #PHP
用PHP实现文件上传二法
Oct 09 #PHP
PHP安装全攻略:APACHE
Oct 09 #PHP
用PHP生成自己的LOG文件
Oct 09 #PHP
VFP与其他应用程序的集成
Oct 09 #PHP
You might like
Access数据库导入Mysql的方法之一
2006/10/09 PHP
用php获取本周,上周,本月,上月,本季度日期的代码
2009/08/05 PHP
Zend framework处理一个http请求的流程分析
2010/02/08 PHP
2个比较经典的PHP加密解密函数分享
2014/07/01 PHP
简单谈谈PHP中的Reload操作
2016/12/12 PHP
基于jquery的无缝循环新闻列表插件
2011/03/07 Javascript
你必须知道的Javascript知识点之&quot;单线程事件驱动&quot;的使用
2013/04/23 Javascript
Bootstrap每天必学之导航条
2015/11/27 Javascript
jquery中ajax跨域方法实例分析
2015/12/18 Javascript
dedecms页面如何获取会员状态的实例代码
2016/03/15 Javascript
Bootstrap导航条的使用和理解3
2016/12/14 Javascript
JS前端笔试题分析
2016/12/19 Javascript
js断点调试经验分享
2017/12/08 Javascript
Python实现抓取城市的PM2.5浓度和排名
2015/03/19 Python
使用python编写简单的小程序编译成exe跑在win10上
2018/01/15 Python
Python中%是什么意思?python中百分号如何使用?
2018/03/20 Python
Django contenttypes 框架详解(小结)
2018/08/13 Python
python集合是否可变总结
2019/06/20 Python
Python 分享10个PyCharm技巧
2019/07/13 Python
python tkinter实现屏保程序
2019/07/30 Python
HTML5本地存储之Database Storage应用介绍
2013/01/06 HTML / CSS
html5 canvas实现圆形时钟代码分享
2013/12/25 HTML / CSS
销售主管岗位职责
2014/02/08 职场文书
《尊严》教学反思
2014/02/11 职场文书
小学运动会入场式解说词
2014/02/18 职场文书
十八届三中全会宣传方案
2014/02/21 职场文书
主要领导对照检查材料
2014/08/26 职场文书
党课培训心得体会
2014/09/02 职场文书
2014年小班保育员工作总结
2014/12/23 职场文书
公司前台接待岗位职责
2015/04/03 职场文书
销售员岗位职责范本
2015/04/11 职场文书
js实现上传图片到服务器
2021/04/11 Javascript
MySQL 逻辑备份与恢复测试的相关总结
2021/05/14 MySQL
浅谈PostgreSQL表分区的三种方式
2021/06/29 PostgreSQL
springboot中的pom文件 project报错问题
2022/01/18 Java/Android
SpringBoot接入钉钉自定义机器人预警通知
2022/07/15 Java/Android