個性留言板php源碼,php留言板源碼

本文目錄一覽:

求php語言編寫的留言板源碼!!!!!!!!!

這是一個簡單的留言本,目前還沒有後台管理程序。如果哪位高手能補上,那就太好了。

演示在

留言保存在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

brBFONT COLOR=”#0000FF” 圖片留言板/FONT/B

center

table width=”800″ border=”1″ bordercolor=”#88CCEE” cellspacing=”0″ cellpadding=”4″ style=”border-collapse:collapse; word-break:break-all”

trtd style=”border-right-style: none”

form method=”post” action=”savemsg.php” style=”font-size: 13px”

 姓名:brinput type=”text” name=”guest_name” maxlength=32 size=32br

 留言:(字數:font color=”#0000FF”span id=sNum0/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;”

trtd

p style=”line-height: 100%; margin-top: 1; margin-bottom: 1″ align=”left”

?php

$perPage=7; //每頁顯示留言數目

$num=$p;

if($num1) $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($prev0)

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/tdtd 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.”brb”.$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”

trtd

p style=”line-height: 100%; margin-top: 2; margin-bottom: 2″ align=”left”

?php

if($prev0)

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.phpRefresh/a”);

if(empty($_POST[‘guest_msg’]))

die(“請填寫留言內容再提交。a href=index.phpRefresh/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寫一個簡單基本的留言板代碼,有點急

資料庫的創建

CREATE DATABASE GBOOK;

CREATE TABLE `gbook` (

`id` INT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,

`name` VARCHAR( 10 ) NOT NULL ,

`sex` TINYINT( 1 ) UNSIGNED NOT NULL ,

`email` VARCHAR( 255 ) NOT NULL ,

`info` TEXT NOT NULL ,

`ip` VARCHAR( 15 ) NOT NULL ,

`time_at` DATETIME NOT NULL

)

主要頁面有:

input.html為初始頁

insert.php為把輸入內容送入資料庫

show.php顯示留言板內容

change.php修改留言板內容的界面

del.php刪除留言板內容

change_ok.php修改留言板內容並送入資料庫

input.html

html

head

meta http-equiv=”content-type” content=”text/html; charset=GB2312″ /

title留言版/title

/head

body

form name=”form1″ method=”post” action=”insert.php”

p你的名字:input type=”text” name=”name” size=”20″ //p

p你的性別:input type=”radio” value=”1″ name=”sex” checked=”checked” /男生 input type=”radio” value=”0″ name=”sex” /女生 /p

p你的E-mail:input type=”text” name=”email” size=”20″ //p

p你的留言內容:/p

ptextarea rows=”9″ name=”info” cols=”35″/textarea/p

pinput type=”submit” value=”提交” name=”B1″ /input type=”reset” value=”重設” name=”B2″ //p

/form

/body

/html

insert.php

?php

$mysql_server_name = “localhost”;

$mysql_username = “root”;

$mysql_password = “123456”;

$mysql_database = “gbook”;

$ip = getenv(‘REMOTE_ADDR’);

$conn = mysql_connect(“localhost”,”root”,”123456″);

mysql_select_db(“gbook”);

$sql = “INSERT INTO `gbook` ( `id` , `name` , `sex` , `email` , `info` , `ip` , `time_at` )

VALUES (NULL , ‘$name’, ‘$sex’, ‘$email’, ‘$info’, ‘$ip’, NOW( ))”;

$result = mysql_query($sql,$conn);

$id = mysql_insert_id();

mysql_close($conn);

?

p留言成功/p

pa href=”show.php”去留言頁 /a/p

show.php

?

$mysql_server_name = “localhost”;

$mysql_username = “root”;

$mysql_password = “123456”;

$mysql_database = “gbook”;

$sql = “SELECT * FROM gbook ORDER BY ‘id’ DESC”; //排序 後留言的在前面顯示

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

while($row = mysql_fetch_row($result))

{ // —-if語句判斷男女——

if($row[2]==1)

{ $gender = ‘男’;}

else

{ $gender = ‘女’; }

?

table width=”752″ border=”1″

tr

td height=”32″p?=$row[6]? ?=$row[5]? /p

p?=$row[1]?(?=$gender?) ?=$row[3]?/p/td

/tr

tr

td height=”45″?=nl2br($row[4])?pa href=”change.php?id=?=$row[0]?”[修改]/a a href=”del.php?id=?=$row[0]?”[刪除]/a/p/td

/tr

/table

hr /

?

}

mysql_free_result($result);

?

change.php

?

$mysql_server_name = “localhost”;

$mysql_username = “root”;

$mysql_password = “123456”;

$mysql_database = “gbook”;

$sql = “SELECT name, sex, email, info FROM gbook WHERE id = ‘$id’ “;

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

?

html

head

meta http-equiv=”content-type” content=”text/html; charset=GB2312″ /

title留言版/title

/head

body

form name=”form1″ method=”post” action=”change_ok.php?id?=$id?”

p你的名字:input type=”text” name=”name” size=”20″ value=”?=$row[0]?”//p

?

// —–if語句判斷男女 1為男 0為女——-

if($row[1]==1)

echo ‘ p你的性別:input type=”radio” value=”1″ name=”sex” checked=”checked” /男 input type=”radio” value=”0″ name=”sex” /女 /p’;

else

echo ‘ p你的性別:input type=”radio” value=”1″ name=”sex” /男 input type=”radio” value=”0″ name=”sex” checked=”checked” /女 /p’;

?

p你的E-mail:input type=”text” name=”email” size=”20″ value=”?=$row[2]?”//p

p你的留言內容:/p

ptextarea rows=”9″ name=”info” cols=”35″?=$row[3]?/textarea/p

pinput type=”submit” value=”提交” /input type=”reset” value=”重設” //p

/form

/body

/html

del.php

?

$mysql_server_name = “localhost”;

$mysql_username = “root”;

$mysql_password = “123456”;

$mysql_database = “gbook”;

$sql = “DELETE FROM gbook WHERE id = ‘$id’ “;

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

mysql_close($conn);

?

pa href=”show.php”[返回]/a/p

change_ok.php

?

$mysql_server_name = “localhost”;

$mysql_username = “root”;

$mysql_password = “123456”;

$mysql_database = “gbook”;

$sql = “UPDATE `gbook` SET `name` = ‘$name’,`sex` = ‘$sex’,`email` = ‘$email’,`info` = ‘$info’ WHERE `id` =’$id’ “;

$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);

mysql_select_db($mysql_database,$conn);

$result = mysql_query($sql);

mysql_close($conn);

?

pa href=”show.php”[返回]/a/p

誰能提供一個PHP留言板源碼

input.htm

html

head

meta http-equiv=”Content-Language” content=”zh-cn”

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

titleinput/title

/head

body

form method=”POST” action=”receive.php”

p您的姓名: input type=”text” name=”T1″ size=”20″/p

p您的性別:男input type=”radio” value=”0″ name=”R1″        

女input type=”radio” name=”R1″ value=”1″/p

p您的EMAIL:input type=”text” name=”T2″ size=”35″/p

p您的留言內容:/p

p textarea rows=”16″ name=”S1″ cols=”45″/textarea/p

p /p

p    input type=”submit” value=”提交” name=”B1″     

input type=”reset” value=”重置” name=”B2″/p

/form

/body

/html

receive.php

?php

$user=’root’;

$password=’123′;

$db=’guestbook’;

$table=’gbook’;

$ip=getenv(REMOTE_ADDR);

$sql = “INSERT INTO `guestbook`.`gbook` (`id`, `name`, `sex`, `email`, `info`, `ip`, `time_at`) VALUES (NULL, ‘$T1’, ‘$R1’, ‘$T2’, ‘$S1’, ‘$ip’, NOW());”;

$connect=mysql_connect(‘localhost’,$user,$password);

mysql_select_db($db);

mysql_query($sql);

$result=mysql_query(“select * from $table”);

while ($arr=mysql_fetch_array($result))

{

if ($arr[2]==0)

$gender=’先生’;

else

$gender=’女士’;

?

html

head

meta http-equiv=”Content-Language” content=”zh-cn”

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

titleReceive/title

/head

body style=”background-attachment: fixed”

table border=”1″ width=”100%” id=”table1″ bgcolor=”#FFFFFF”

tr

td bordercolor=”#FFFFFF” bgcolor=”#C0C0C0″?=$arr[6]?(?=$arr[5]?)p?=$arr[1]? ?=$gender?a href=”?=$arr[3]?”?=$arr[3]?/a

寫到:/td

/tr

tr

td?=$arr[4]?p /p

pa href=”del.php?id=?=$arr[0]?”[刪除]/a        

a href=”modify.php?id=?=$arr[0]?”[修改]/a]/td

/tr

/table

/body

/html

?php

echo ‘p’;

echo ‘p’;

}

?

html

head

meta http-equiv=”Content-Language” content=”zh-cn”

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

title新建網頁 1/title

/head

body

pa href=”input.htm”繼續留言/a/p

/body

/html

del.php

?php

$user=’root’;

$password=’123′;

$db=’guestbook’;

$table=’gbook’;

$sql=”DELETE FROM $table WHERE id=$id”;

$connect=mysql_connect(‘localhost’,$user,$password);

mysql_select_db($db);

$result=mysql_query($sql);

if ($result)

echo “刪除成功”;

else

echo “刪除失敗”;

?

html

head

meta http-equiv=”Content-Language” content=”zh-cn”

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

title新建網頁 1/title

/head

body

pa href=”receive.php”返回首頁/a/p

/body

/html

modify.php

?php

$user=’root’;

$password=’123′;

$db=’guestbook’;

$table=’gbook’;

$ip=getenv(REMOTE_ADDR);

$connect=mysql_connect(‘localhost’,$user,$password);

mysql_select_db($db);

$result=mysql_query(“select * from $table where id=$id”);

$arr=mysql_fetch_array($result);

?

html

head

meta http-equiv=”Content-Language” content=”zh-cn”

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

titleinput/title

/head

body

form method=”POST” action=”modify_ok.php?id=?=$id?”

p您的姓名: input type=”text” name=”T1″ size=”20″ value=”?=$arr[1]?”/p

p您的性別:

?php

if ($arr[2]==0) echo ‘男input type=”radio” value=”0″ name=”R1″ checked        

女input type=”radio” name=”R1″ value=”1″/p’;

else echo ‘男input type=”radio” value=”0″ name=”R1″        

女input type=”radio” name=”R1″ value=”1″ checked/p’;

?

p您的EMAIL:input type=”text” name=”T2″ size=”35″ value=”?=$arr[3]?”/p

p您的留言內容:/p

p textarea rows=”16″ name=”S1″ cols=”45″ ?=$arr[4]?/textarea/p

p /p

p    input type=”submit” value=”修改” name=”B1″     

input type=”reset” value=”重置” name=”B2″/p

/form

/body

/html

modify_ok.php

?php

$user=’root’;

$password=’123′;

$db=’guestbook’;

$table=’gbook’;

$connect=mysql_connect(‘localhost’,$user,$password);

mysql_select_db($db);;

$sql = “UPDATE `guestbook`.`gbook` SET `name` = ‘$T1’, `sex` = ‘$R1’, `email` = ‘$T2’, `info` = ‘$S1’ WHERE `gbook`.`id` = ‘$id’ LIMIT 1;”;

$result=mysql_query($sql);

if ($result)

echo “修改成功”;

else

echo “修改失敗”;

?

html

head

meta http-equiv=”Content-Language” content=”zh-cn”

meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″

title新建網頁 1/title

/head

body

pa href=”input.htm”繼續留言/a/p

/body

/html

原創文章,作者:KKAUT,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/324949.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
KKAUT的頭像KKAUT
上一篇 2025-01-13 13:23
下一篇 2025-01-13 13:23

相關推薦

  • PHP和Python哪個好找工作?

    PHP和Python都是非常流行的編程語言,它們被廣泛應用於不同領域的開發中。但是,在考慮擇業方向的時候,很多人都會有一個問題:PHP和Python哪個好找工作?這篇文章將從多個方…

    編程 2025-04-29
  • 雲智直聘 源碼分析

    本文將會對雲智直聘的源碼進行分析,包括前端頁面和後端代碼,幫助讀者了解其架構、技術實現以及對一些常見的問題進行解決。通過本文的閱讀,讀者將會了解到雲智直聘的特點、優勢以及不足之處,…

    編程 2025-04-29
  • PHP怎麼接幣

    想要在自己的網站或應用中接受比特幣等加密貨幣的支付,就需要對該加密貨幣擁有一定的了解,並使用對應的API進行開發。本文將從多個方面詳細闡述如何使用PHP接受加密貨幣的支付。 一、環…

    編程 2025-04-29
  • 使用PHP foreach遍歷有相同屬性的值

    本篇文章將介紹如何使用PHP foreach遍歷具有相同屬性的值,並給出相應的代碼示例。 一、基礎概念 在講解如何使用PHP foreach遍歷有相同屬性的值之前,我們需要先了解幾…

    編程 2025-04-28
  • Python網站源碼解析

    本文將從多個方面對Python網站源碼進行詳細解析,包括搭建網站、數據處理、安全性等內容。 一、搭建網站 Python是一種高級編程語言,適用於多種領域。它也可以用於搭建網站。最常…

    編程 2025-04-28
  • 源碼是什麼

    源碼是一段計算機程序的原始代碼,它是程序員所編寫的可讀性高、理解性強的文本。在計算機中,源碼是指編寫的程序代碼,這些代碼按照一定規則排列,被計算機識別並執行。 一、源碼的組成 源碼…

    編程 2025-04-27
  • PHP獲取301跳轉後的地址

    本文將為大家介紹如何使用PHP獲取301跳轉後的地址。301重定向是什麼呢?當我們訪問一個網頁A,但是它已經被遷移到了另一個地址B,此時若伺服器端做了301重定向,那麼你的瀏覽器在…

    編程 2025-04-27
  • Go源碼閱讀

    Go語言是Google推出的一門靜態類型、編譯型、並髮型、語法簡單的編程語言。它因具有簡潔高效,內置GC等優秀特性,被越來越多的開發者所鍾愛。在這篇文章中,我們將介紹如何從多個方面…

    編程 2025-04-27
  • PHP登錄頁面代碼實現

    本文將從多個方面詳細闡述如何使用PHP編寫一個簡單的登錄頁面。 1. PHP登錄頁面基本架構 在PHP登錄頁面中,需要包含HTML表單,用戶在表單中輸入賬號密碼等信息,提交表單後服…

    編程 2025-04-27
  • Python怎麼看源碼

    本文將從以下幾個方面詳細介紹Python如何看源碼,幫助讀者更好地了解Python。 一、查看Python版本 在查看Python源碼之前,首先需要確認Python版本。可以在命令…

    編程 2025-04-27

發表回復

登錄後才能評論