<?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['pubmsg'])){ $username=$_POST['username']; $title=$_POST['title']; $content=$_POST['content']; $time=time(); $data=compact('username','title','content','time'); array_push($msgs,$date); $msgs=serialize($msgs); //序列号变成字符串 if(file_put_contents($filename,$msgs)){ echo "<script>alert('留言成功!');location.href='webpage.php';</script>"; }else{ echo "<script>alert('留言失败!');location.href='webpage.php';</script>"; } } ?><!DOCTYPE html><html><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><div><div><div><h1>this is Pan show time</h1></div> <?php if(is_array($msgs)&&count($msgs)>0):?><table><thead><tr><th>编号</th><th>用户</th><th>标题</th> <th> 时间 </th> <th>内容</th></tr></thead><tbody> <?php $i=1;foreach($msgs as $val):?><tr><td><?php echo $i++; ?></td><td> <?php echo $var['username']; ?></td><td> <?php echo $var['title']; ?> </td> <td> <?php echo date("Y-m-d H:i:s",$var['time']);?> </td><td><?php echo $val['content'];?></td></tr><?php endforeach; ?></tbody></table> <?php endif;?><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" cols="30" rows="5" required></textarea> <hr color="pink"> <button type="submit" name="pubmsg">提交</button></fieldset></form></div></div></div></body></html>
- 2 回答
- 0 关注
- 1192 浏览
添加回答
举报
0/150
提交
取消