侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

php+dbfile开发小型留言本

php  /  管理员 发布于 7年前   165


最近一直在用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是留言显示和提交页面。代码拷贝框
<?phprequire_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="https:/article/':'').(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中。代码拷贝框
<?phprequire_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="https:/article/':'').(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 编写的日历
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客