當前位置:首頁 » 編程語言 » php簡單留言板源碼

php簡單留言板源碼

發布時間: 2023-07-28 07:19:51

『壹』 求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]

熱點內容
紅帆oa伺服器地址查詢 發布:2025-02-07 14:31:41 瀏覽:657
文本框腳本圖片 發布:2025-02-07 14:23:28 瀏覽:231
少兒編程c語言 發布:2025-02-07 14:22:50 瀏覽:218
一階低通濾波器c語言 發布:2025-02-07 14:22:37 瀏覽:852
電腦的東西為什麼粘貼不到伺服器 發布:2025-02-07 14:21:04 瀏覽:197
手機脫模解壓視頻 發布:2025-02-07 14:20:18 瀏覽:473
密碼多少密碼多少密碼多少密碼 發布:2025-02-07 14:07:30 瀏覽:857
我的世界啟動器電腦伺服器 發布:2025-02-07 14:07:27 瀏覽:484
愛加密深圳科技有限 發布:2025-02-07 14:07:26 瀏覽:87
c語言密碼星號 發布:2025-02-07 14:07:24 瀏覽:801