本文目录一览:
在网上下载的PHP留言板源码 要怎样才能浏览它整站的一个效果呢/ PHP文件都是分开编写的
你搭建一个php环境,实在不会可以下载一个wamp集成安装,然后把这个项目全部放在一个文件夹里,之后放在wamp安装目录下一个www的文件夹里。之后通过浏览器,输入:localhost,点击你新建的那个文件夹就可以
求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"-php网页留言板源码
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-php网页留言板源码
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;"-php网页留言板源码
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;"-php网页留言板源码
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"-php网页留言板源码
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留言板源码
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());";-php网页留言板源码
$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 -php网页留言板源码
写到:/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;";-php网页留言板源码
$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