首先是Index页面效果图

index.php

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
//检测文件是否存在
if(file_exists($filename)){
//读取文件中的内容
$string=file_get_contents($filename);
if(strlen($string)>0){
$msgs=unserialize($string);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
简易留言板-<span>V1.0</span>
</h1>
</div>
<div class="hero-unit">
<h1>
Hello, world!
</h1>
<p>
这是一个可视化布局模板, 你可以点击模板里的文字进行修改, 也可以通过点击弹出的编辑框进行富文本修改. 拖动区块能实现排序.
</p>
<p>
<a rel="nofollow" class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<?php if(is_array($msgs)&&count($msgs)>0):?>
<table class="table">
<thead>
<tr>
<th>
编号
</th>
<th>
用户名
</th>
<th>
标题
</th>
<th>
时间
</th>
<th>
内容
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody>
<?php $i=1;foreach($msgs as $key=>$val):?>
<tr class="success">
<td>
<?php echo $i++;?>
</td>
<td>
<?php echo $val['username'];?>
</td>
<td>
<?php echo $val['title'];?>
</td>
<td>
<?php echo date("m/d/Y H:i:s",$val['time']);?>
</td>
<td>
<?php echo $val['content'];?>
</td>
<td>
<a href="edit.php?id=<?php echo $key;?>">编辑</a>|<a href="#" onclick="show_confirm(<?php echo $key;?>)">删除</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php endif;?>
<input type="button" class="btn btn-primary btn-lg" name="pubMsg" value="我要留言" onclick="window.location.href='add.php'"/>
</div>
</div>
</div>
<script type="text/javascript">
function show_confirm(key){
var r=confirm("确定删除吗?");
if (r==true){
location.href='delete.php?id='+key;
}
}
</script>
</body>
</html>

然后是新增留言页面效果图

add.php

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
//检测文件是否存在
if(file_exists($filename)){
//读取文件中的内容
$string=file_get_contents($filename);
if(strlen($string)>0){
$msgs=unserialize($string);
}
}
//检测用户是否点击了提交按钮
if(isset($_POST['addMsg'])){
$username=$_POST['username'];
$title=strip_tags($_POST['title']);
$content=strip_tags($_POST['content']);
$time=time();
//将其组成关联数组
$data=compact('username','title','content','time');
array_push($msgs,$data);
$msgs=serialize($msgs);
if(file_put_contents($filename,$msgs)){
echo "<script>alert('留言成功!');location.href='index.php';</script>";
}else{
echo "<script>alert('留言失败!');location.href='index.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
简易留言板-<span>V1.0</span>
</h1>
</div>
<div class="hero-unit">
<h1>
你终于来了!
</h1>
<p>
这是一个添加留言的留言板,你在下面愉快的留言吧!
</p>
<p>
<a rel="nofollow" class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<form action="#" method="post">
<fieldset>
<legend>发布</legend>
<label>用户名</label><input type="text" name="username" required />
<label>标题</label><input type="text" name="title" required />
<label>内容</label><textarea name="content" rows="5" cols="30" required></textarea>
<hr>
<input type="submit" class="btn btn-primary btn-lg" name="addMsg" value="发布留言"/>
<input type="button" class="btn btn-primary btn-lg" value="查看留言" onclick="window.location.href='index.php'"/>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>

编辑留言页面

edit.php

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
$id=$_GET['id'];//获取id
//检测文件是否存在
if(file_exists($filename)){
//读取文件中的内容
$string=file_get_contents($filename);
if(strlen($string)>0){
$msgs=unserialize($string);
}
}
//获取已有的留言信息
$username=$msgs[$id]['username'];
$title=strip_tags($msgs[$id]['title']);
$content=strip_tags($msgs[$id]['content']);
$time=$msgs[$id]['time'];
//检测用户是否点击了编辑按钮
if(isset($_POST['editMsg'])){
//将修改后的留言写入文档
$msgs[$id]['username']=$_POST['username'];
$msgs[$id]['title']=strip_tags($_POST['title']);
$msgs[$id]['content']=strip_tags($_POST['content']);
$msgs[$id]['time']=time();
$msgs=serialize($msgs);
if(file_put_contents($filename,$msgs)){
echo "<script>alert('编辑成功!');location.href='index.php';</script>";
}else{
echo "<script>alert('编辑失败!');location.href='index.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
简易留言板-<span>V1.0</span>
</h1>
</div>
<div class="hero-unit">
<h1>
再来修改下~
</h1>
<p>
这是用来修改留言的地方哦!
</p>
<p>
<a rel="nofollow" class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<form action="#" method="post">
<fieldset>
<legend>编辑</legend>
<label>用户名</label><input type="text" name="username" value="<?php echo $username;?>" required />
<label>标题</label><input type="text" name="title" value="<?php echo $title;?>" required />
<label>内容</label><textarea name="content" rows="5" cols="30" required><?php echo $content;?></textarea>
<hr>
<input type="submit" class="btn btn-primary btn-lg" name="editMsg" value="编辑完成"/>
<input type="button" class="btn btn-primary btn-lg" value="查看留言" onclick="window.location.href='index.php'"/>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>

此时储存的留言信息:msg.txt

a:2:{i:3;a:4:{s:8:"username";s:3:"cyy";s:5:"title";s:12:"cyy又来了";s:7:"content";s:27:"cyy经常来留言!!!";s:4:"time";i:1565510381;}i:4;a:4:{s:8:"username";s:3:"cyy";s:5:"title";s:17:"cyy2020第一踩~";s:7:"content";s:17:"cyy2020第一踩~";s:4:"time";i:1578723602;}}

php实现简易留言板效果的更多相关文章

  1. DOM操作相关案例 模态对话框,简易留言板,js模拟选择器hover,tab选项卡,购物车案例

    1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <h ...

  2. JSP简易留言板

    写在前面 在上篇博文JSP内置对象中介绍JSP的9个内置对象的含义和常用方法,但都是比较理论的知识.今天为大家带来一个小应用,用application制作的简易留言板. 包括三个功能模块:留言提交.留 ...

  3. 原生node实现简易留言板

    原生node实现简易留言板 学习node,实现一个简单的留言板小demo 1. 使用模块 http模块 创建服务 fs模块 操作读取文件 url模块 便于path操作并读取表单提交数据 art-tem ...

  4. Flask学习之旅--简易留言板

    一.写在前面 正所谓“纸上得来终觉浅,方知此事要躬行”,在看文档和视频之余,我觉得还是要动手做点什么东西才能更好地学习吧,毕竟有些东西光看文档真的难以理解,于是就试着使用Flask框架做了一个简易留言 ...

  5. 微信小程序实现简易留言板

    微信小程序现在很火,于是也就玩玩,做了一个简易的留言板,让大家看看,你们会说no picture you say a j8 a,好吧先上图. 样子就是的,功能一目了然,下面我们就贴实现的代码,首先是H ...

  6. 用js做一个简单的留言板效果

    html部分: 1: <!DOCTYPE> 2: <html lang="zh-en"> 3: <head> 4: <title>j ...

  7. vue实现简易留言板

    首先引入vue.js <script src="vue.js"></script> 布局 <div id="div"> &l ...

  8. js简易留言板

      <!DOCTYPE html>   <html lang="en">   <head>   <meta charset="U ...

  9. js 实现简易留言板功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. 查看php相关信息

    1.最常见的就是 创建一个  php页面  ,例如 test.php,  内容如下 <?php phpinfo();?> 直接访问 这个页面,就可以看到php的 信息了 2.其它方法  直 ...

  2. Rip 动态路由协议

            路由信息协议(RIP) 是内部网关协议IGP中最先得到广泛使用的协议.        Routing Information Protocol) RIP是一种分布式的基于距离矢量的路由 ...

  3. Vscode开发Java环境搭建

    VSCode 开发 JAVA 微软为 Java 开发者推出了一个 Visual Studio Code 的安装程序.Visual Studio Code 中目前提供了许多 Java 扩展. 该软件包可 ...

  4. Force removing ActivityRecord no saved state问题的原因分析

    关键字,crash Force removing ActivityRecord,app died, no saved state的原因 相机拍摄的过程中断电,拍了一张黑图 I/ActivityMana ...

  5. JMeter函数助手中Random函数详解

    1.__Random函数的生成 The minimum value allowed for a range of values:一个范围内允许的最小值 The maximum value allowe ...

  6. C#设计模式学习笔记:(18)状态模式

    本笔记摘抄自:https://www.cnblogs.com/PatrickLiu/p/8032683.html,记录一下学习过程以备后续查用. 一.引言 今天我们要讲行为型设计模式的第六个模式--状 ...

  7. 微信小程序入门笔记-账号注册(1)

    小程序注册 微信小程序开发之前,必须先有小程序账号,下面是注册步骤: 1.打开网页 微信公众平台https://mp.weixin.qq.com/,点击立即注册按钮 2.注册类型 选择小程序开发 3. ...

  8. 仁和药业顺利出局,布局地产万科A

    仁和药业布局到第二单,被止盈了,盈利大约1.1%.这几日地产行业回调明显,所以布局了万科A. 资金量W11.8 建仓价格28.6 加仓系数1.5 加仓间隔2.70% 总盈利比6.50% 期待吧!

  9. PMP--2. 项目启动前准备工作

    ####################################################### 概述:在第一章节的1.1-1.7中基本都是介绍的<PMBOK>的理论概念以及 ...

  10. .Net框架的模块代码生成器--其三(dotnet tool指令的参数)

    别人已经写好了一个这种处理指令参数的库,我们这里是使用别人的库来实现规范的指令系统 继续上一篇的gfile或者新建一个.Net Core控制台程序也可以 1.安装nuget包,程序包管理器控制台运行 ...