php简单留言板源码
这是一个简单的留言本,目前还没有后台管理程序。如果哪位高手能补上,那就太好了。
演示在http://www.ideawu.net/person/liuyan
留言保存在message.txt文件中,留言的格式为:date<$>ip<$>name<$>content
"<$>"为分隔符号
注意:源码文件和message.txt文件必须以gbk格式保存。如果你不知道如何保存文件为gbk格式,请咨询你的文本编辑器软件提供商。
/****************************************
* 本代码可以用作任何用途,但是与作者无关。
* 也就是,你使用本代码获取收益或者因此受
* 到损害,后果与作者无关。
****************************************/
file: index.php
代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>留言板</title>
<link rel="stylesheet" href="../msg.css" type="text/css">
</head>
<body>
<br><B><FONT COLOR="#0000FF">图片留言板</FONT></B>
<center>
<table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
<tr><td style="border-right-style: none">
<form method="post" action="savemsg.php" style="font-size: 13px">
姓名:<br><input type="text" name="guest_name" maxlength=32 size=32><br>
留言:(字数:<font color="#0000FF"><span id=sNum>0</span></font>/256)<br>
<textarea class="textForm" name="guest_msg" cols="64" rows="8" onkeyup="sNum.innerHTML=this.value.length"></textarea><br>
<input class="button" type="submit" name="submit" value="发表留言">
<input class="button" type="reset" value="重置" name="reset">
</form>
</td></tr>
</table>
<?php
include("showmsg.php");
if(!empty($_GET['p'])){
$num=$_GET['p'];
showpage($num);
}else showpage(1);
?>
</center>
</body>
</html>
file: showmsg.php
代码:
<?php
function showpage($p)
{ ?>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px;">
<tr><td>
<p style="line-height: 100%; margin-top: 1; margin-bottom: 1" align="left">
<?php
$perPage=7; //每页显示留言数目
$num=$p;
if($num<1) $num=1;
$prev=$num-1;
$next=$num+1;
$page=$num-1; //当前页码
$fname="message.txt"; //存储留言的文件
$all_msg=file($fname); //将留言读入数组
$line_count=count($all_msg);
$page_count=ceil($line_count/$perPage);
if($prev>0)
echo "<a href=index.php?p=$prev>上一页</a>";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<table width="800" border="1" bordercolor="#88CCEE" cellpadding="3" cellspacing="0" style="border-collapse:collapse; font-size:12px; word-break:normal; table-layout:fixed;">
<tr height="18" bgcolor="#5FBEF8"><td width="20%">
<b>留言时间/留言者</b></td><td width="86%"><b>留言内容</b>
</td></tr>
<?php
//显示留言
$bg1="#FBF9F9"; $bg2="#E9EFF4";$bg=$bg2;
for($n=$line_count-1-$page*$perPage;$line_count-1-$page*$perPage-$n<$perPage;$n--){
$bg=($bg==$bg1)? $bg2:$bg1; //变换背景颜色
if(!empty($all_msg[$n])){
list($date,$ip,$name,$msg)=explode("<$>",$all_msg[$n],4); //获取留言内容
echo "<tr bgcolor=$bg>";
echo "<td width=14%>".$date."<br><b>".$name."</b></td>";
echo "<td width=86%>".$msg."</td>";
echo "</tr>";
}
}
?>
</table>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px">
<tr><td>
<p style="line-height: 100%; margin-top: 2; margin-bottom: 2" align="left">
<?php
if($prev>0)
echo "<a href=index.php?p=$prev>上一页</a>";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<?php } ?>
file: savemsg.php
代码:
<?php
$MSG_MAX_LEN=512; //留言最大长度
if (getenv("HTTP_CLIENT_IP"))
$ip= getenv("HTTP_CLIENT_IP");
elseif (getenv("HTTP_X_FORWARDED_FOR"))
$ip= getenv("HTTP_X_FORWARDED_FOR");
else
$ip= getenv("REMOTE_ADDR");
//获取IP地址结束
$date=date("Y年m月d日 H:i:s",time());
if(empty($_POST['guest_name']))
die("请填你的名字。<a href=index.php>Refresh</a>");
if(empty($_POST['guest_msg']))
die("请填写留言内容再提交。<a href=index.php>Refresh</a>");
$guest_name=strip_tags($_POST['guest_name']);
$guest_msg=substr($_POST['guest_msg'],0,$MSG_MAX_LEN);
//write message to file
//make the message be a line when stored
$guest_msg = str_replace( "\r\n", "\n", $guest_msg);
$guest_msg = str_replace( "\r", "\n", $guest_msg);
$guest_msg = str_replace(" "," ",$guest_msg);
$guest_msg = str_replace(">",">",$guest_msg);
$guest_msg = str_replace("<","<",$guest_msg);
$guest_msg = str_replace("\'","'",$guest_msg);
$guest_msg = nl2br($guest_msg);
//保存留言,以追加的形式
$fname="message.txt";
$fp=fopen($fname,"a+");
fwrite($fp,$date."<$>".$ip."<$>".$guest_name."<$>".$guest_msg."\n");
fclose($fp);
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
?>
用于显示效果的样式表文件
file: msg.css
代码:
A:link {
color: #0033FF;
text-decoration: none;
}
A:visited {
color: #0033FF;
text-decoration: none;
}
A:hover {
color: #30A300;
text-decoration: underline;
}
A:active {
color: #0036A9;
text-decoration: none;
}
BODY{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
background: #FBF9F9;
}
TABLE{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
border-collapse: collapse;
table-layout: fixed;
margin: 0px;
}
‘贰’ 关于php简易留言板的一小段代码..
我先给每行程序加上注释
<?php
$name=$_POST['name'];//获取表单提交过来的数据
$note=$_POST['note'];//同上
$db=new mysqli('localhost','root','123','dlw');//连接mysql数据库并选择dlw数据库,很老的写法了,不建议这么使用。
$sql="insert into gustbook values(name,time,words)";//sql语句
$sql=$sql.$name;//等同于sql .= $name 相当于让上面那条sql语句后面连接$name但是这里在$name前面漏掉了一个( 应该是$sql = $sql."(".$name
$sql=$sql."',now(),'".$note."')";//同上
$result=$db->query($sql);//执行sql语句
echo"<center>write successfully.</center><br><br>";//输出write successfully字符串,没有任何意义,因为不管执行成不成功他都输出。
?>
<html>
<body bgcolor="FFCCCC">
<center>
<a href="do.php">write again</a><br><br>
<a href="index.php">check out the message</a>
</center>
</body>
</html>
这应该是个很老的程序,你要用首先要改正几个地方的写法
1、$db=new mysqli('localhost','root','123','dlw');
最好写成
mysql_connect('localhost','root','123');
mysql_slect_db('dlw');
2、 $sql="insert into gustbook values(name,time,words)";
$sql=$sql.$name;
$sql=$sql."',now(),'".$note."')";
可以写一个sql语句就可以了,不用去连接,而且最好用标准的写法。
$sql = "insert into gustbook (name,time,words) values ('".$name."',now(),'".$note."')";
3.$result=$db->query($sql);
echo"<center>write successfully.</center><br><br>";
加一个写入成功的判断
if(mysql_query($sql)){//注意这里不是$db因为我们前面把mysqli这个类已经省掉了。
echo"<center>write successfully.</center><br><br>";
}else{
"<center>write false.</center><br><br>";
}
具体留言不成功,可能还有几个问题,首先你的数据库有没有这几个字段,还有具体有没有连接成功数据库,你可以用phpmyadmin看一看你的留言内容是不是已经写入数据库,如果有但没显示,那应该是读取时候的问题,就不是你这个程序的问题了。
你用我给说的写法试一下也不行吗。
mysql_slect_db('dlw');
你确定数据库连接成功了吗,
把mysql_connect('localhost','root','123');改为
mysql_connect('localhost','root','123') or die("数据库连接不成功");
如果数据没有进去,那就跟index.php没有任何关系,我看一下你现在的这个程序。表单还有添加的程序,还有数据表的结构。
‘叁’ php制作留言板代码
<form action="留言方法,也可以是留言.php文件,也可以是当前页面" method="get">
<p>First name: <input type="text" name="fname" /></p>
<p>Last name: <input type="text" name="lname" /></p>
<input type="submit" value="Submit" />
</form>
php:
$fname=$_GET[fname];
$lname=$_GET[lname];
$sql = "insert into 表名(字段1,字段2) values('$fname','$lname')";
if(!$sql ){
return "插入失败";
}else{
return "成功添加数据";
}
‘肆’ 谁有留言板或者表白墙的PHP源码
您好,很高兴为您解答。
【id】这个算是父Id 可以通过这个id来查询 在这个id下是否有子id 同时也可以记录这个是那条留言的id
【 son_id】这个是子id 然后通过这个id 可以找到相对应的父id
【 news_id】记录文章的id
【sender_author】接受留言的人
【receiver_author】发送留言的人
【content】留言的内容
【status】在有人回复你的帖子的时候 这个值从0转为1时候 该消息不在显示 如果没点击进去 该消息依然存在
【time】记录留言的时间
留言板回复思路
当发送方(也就留言的人)要到该文章下留言或者回复的的时候就需要接收方(也就文章的作者或者要被回复的人)来接收。单数据库语句查询到这个键sender_author和receiver_author 的是就会知道接收方是谁和发送方是谁了。然后在根据这个判断来显示出回复内容。
提示你有一条新的消息思路
当发送方发送消息的时候 这个status的值默认为0 就是提示接收发 你有一条新的消息。当点击进去的时候 调用数据库修改语句把指定的值修改成为1 这样就不显示了 。
查看评论的时候 的数据库操作语句
functionmessage($id){
$query=$this->db->query("SELECT*FROMmessageWHEREnews_id='$id'");//或者文章id后查询里面所有评论
return$query->result();
}
这个是获取父的留言内容的代码
<?phpforeach($queryas$sel){?>
<p>留言用户:<?phpecho$sel->receiver_author;?>留言内容:<?phpecho$sel->content?></p>
<?php}?>
用户是否登陆 并给予留言权限
<formid="form1"name="form1"method="post"action="<?phpechosite_url()."/publish/user_message"?>">
<textarearows="5"cols="50"name="huifu"<?phpif($uere_name=="0"){echo"disabled";}?>>
<?php
if($uere_name=="0")
{echo"抱歉你还没登录不能进行留言";}
?>
</textarea>
<inputclass="wole"name="author"value="<?phpecho$author;?>"/><!--接受方帖子作者-->
<inputclass="wole"name="news_id"value="<?phpecho$news_idx;?>"/><!--文章id-->
<inputtype="submit"name="Submit"/>
</form>
<scriptlanguage="javascript">
functionupdateinfo(){
if(<?phpecho$uere_name;?>==1){
document.form1.Submit.value="留言";
document.form1.Submit.disabled=false;
}
else{
document.form1.Submit.value="还未登录";
document.form1.Submit.disabled="disabled";
}
}
updateinfo();
</script>
这个是显示了 获取指定的父id 之后来显示他里面的全部子id 和留言内容
<p>这里是<?phpecho$is;?>楼用户:<?phpecho$sel->receiver_author;?><br/>留言内容:<?phpecho$sel->content?>
<aonClick="showdiv('contentid<?phpecho$is;?>','showtext<?phpecho$is;?>')"href="javascript:void(0)">回复</a>
<divid="contentid<?phpecho$is;?>"class="none">
<?php
$query=$this->db->query("select*frommessagewhereson_id='$sel->id'orderbyid");//获取指定父id的子回复
$revis=$query->result();
foreach($revisas$row){?>
<p><?phpif($row->sender_author==$row->receiver_author){echo$row->sender_author;}
else{echo$row->sender_author."回复了:".$row->receiver_author;}?>
内容是:<?phpecho$row->content?></p>
<?php}?>
<formaction="<?phpechosite_url()."/publish/son_message"?>"method="post">
<inputname="son_idx"class="wole"value="<?phpecho$sel->id?>"/>
<inputname="receiver_author"class="wole"value="<?phpecho$sel->receiver_author;?>"/>
<inputclass="wole"name="news_id"value="<?phpecho$news_idx;?>"/><!--文章id-->
<textarearows="5"cols="50"name="huifux"></textarea>
<br><inputtype="submit"name="sub"value="回复"></form></div></p>
<scriptlanguage="JavaScript"type="text/JavaScript">
<!--
functionshowdiv(targetid,objN){
vartarget=document.getElementById(targetid);
varclicktext=document.getElementById(objN)
if(target.style.display=="block"){
target.style.display="none";
clicktext.innerText="回复";
}else{
target.style.display="block";
clicktext.innerText='收起';
}
}
-->
</script>
如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】
希望我的回答对您有所帮助,望采纳!
~ O(∩_∩)O~
‘伍’ 谁能提供一个PHP留言板源码
我自己有一个简单的留言板系统,
里面有简单的增删改查功能,需要会数据库。
希望可以帮助到有缘的学习爱好者。
这是首页index.php代码:
<html>
<head>
<title>我的留言本</title>
<script type ="text/javascript">
function dodel(id){
if(confirm("确定要删除吗?")){
window.location="action.php?action=del&id="+id;
}
}
</script>
<style type = "text/css">
*{font-family:"微软雅黑";}
body{
background:url(images/bg.gif);
}
a{color:#000;text-decoration:none;}
a:hover{text-decoration:underline;}
td{text-align:center;}
table{
border:3px solid #9b9b9b;
background:#E9E9E9;
}
td{
color:#660000;
}
</style>
</head>
<body>
<center>
<?php include("menu.php"); ?>
<h3>浏览新闻</h3>
<table width ="880" border="1" cellpadding="3">
<tr>
<th>新闻id</th><th>新闻标题</th><th>关键字</th><th>作者</th><th>发布时间</th><th>新闻内容</th><th>操作</th>
</tr>
<?php
//1.导入配置文件
require("dbconfig.php");
//2.链接mysql数据库,选择数据库
$link = @mysql_connect(HOST,USER,PASS)or die("数据库连接失败!");
mysql_select_db(DBNAME,$link);
//3.执行查询,并返回结果
$sql="select * from news order by addtime desc";
$result = mysql_query($sql,$link);
//4.解析结果集,并遍历输出
while($row = mysql_fetch_assoc($result)){
echo"<tr>";
echo"<td>{$row['id']}</td>";
echo"<td>{$row['title']}</td>";
echo"<td>{$row['keywords']}</td>";
echo"<td>{$row['author']}</td>";
echo"<td>{$row['addtime']}</td>";
echo"<td>{$row['content']}</td>";
echo"<td>
<a href='javascript:dodel({$row['id']})'>删除</a>
<a href='edit.php?id={$row['id']}'>修改</a></td>";
echo"</tr>";
}
//5.释放结果集
mysql_free_result($result);
mysql_close($link);
?>
</table>
</center>
</body>
</html>
‘陆’ 求php留言板代码,就是按提交后直接显示在页面的,在留言,再增加一条
[M][ftc=#EE1000][fts=6][ftf=Webdings]Y[/ft][/ft][/ft]
[ftc=#00BFF3]﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌[/ft]
[ftc=#FFF100]对
自
己
好
点,
因
为
一
辈
子
不
长;[/ft]
[ffg,#F68E54,#FFFFFF]对
身
边
的
人
好
点,因
为
下
辈
子
不
一
定
能
够
遇
见。[/ft]
[ftc=#00BFF3]——————————————————————————
[ftc=#EE1D24]◣[/ft][ftc=#FFF100]◤[/ft]
[ftc=#37B400]◢[/ft][ftc=#00AEEF]◥[/ft][/M][M][/M][M][/M][M][/M][M][/M][M][/M]
[M][ftc=000000][/ft][/M][/ft][/ft][/ft][/ft][/ft][/ft][/ft][/ft][/ft][/ft][/M][/M][/M][/M][/M][/M][/M][/M][/M][/M][/M][/M][/M]