当前位置: 首页 > 图文教程 > 网络编程 > PHP > 一个可分页的基于文本的PHP留言板源码

PHP
PHP新手总结的PHP基础知识
php实现gb2312和unicode间编码转换
用php语言实现数据库连接详细代码介绍
详细解析 PHP 向 MySQL 发送数据过程
利用PHP V5开发多任务应用程序
详细讲解PHP中缓存技术的应用
php escapeshellcmd多字节编码漏洞
《PHP设计模式介绍》导言
《PHP设计模式介绍》第一章 编程惯用法
《PHP设计模式介绍》第二章 值对象模式
《PHP设计模式介绍》第三章 工厂模式
《PHP设计模式介绍》第四章 单件模式
《PHP设计模式介绍》第五章 注册模式
《PHP设计模式介绍》第六章 伪对象模式
《PHP设计模式介绍》第七章 策略模式
《PHP设计模式介绍》第八章 迭代器模式
《PHP设计模式介绍》第九章 观测模式
《PHP设计模式介绍》第十章 规范模式
《PHP设计模式介绍》第十一章 代理模式
《PHP设计模式介绍》第十二章 装饰器模式

一个可分页的基于文本的PHP留言板源码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 258 ::
收藏到网摘: n/a

小弟初学PHP,编了一个留言板程序,自我感觉良好,故厚着脸皮放了上来,请各位大哥指正。源程序如下:
<?php
//文件名:guest.php
//设定部分
$guestfile="guest";//纪录留言的文本文件
$home="index.html";//返回的主页
$imagedir="image"; //图像文件的目录
$backimage=$imagedir."/upload/tech/20091012/20091012014114_bca82e41ee7b0833588399b1fcd177c7.gif";//背景图像
$backcolor="#ceffff";//背景颜色,在$backimage=""时起作用
?>
<html>
<head>
<?php
if($QUERY_STRING!="") {
$page = $QUERY_STRING;
} else {
$page = 1;
}
if($mode=="add"){
$name=htmlspecialchars(trim($name));
$title=htmlspecialchars(trim($title));
$data=nl2br(htmlspecialchars($data));
$data=str_replace("r","",$data);
$data=str_replace("x0A","",$data);
$data=str_replace(" "," ",$data);
if($data=="") $data=" ";
$e_mail=trim($e_mail);
if($e_mail=="") $e_mail=0;
$url=trim($url);
if($url=="http://" || $url=="") $url=0;
$time=date("Y")."年".date("m")."月".date("d")."日[".date("H").":".date("i").":".date("s")."]";
if($name=="" || $title==""){
echo "<script Language="JavaScript">n";
echo " alert("请至少输入姓名与留言标题。");n";
echo "history.back();";
echo "</script></head></html>n";
exit;
}
$adddata=$name."t".$e_mail."t".$url."t".$title."t".$data."t".$icon."t".$time."n";
if(file_exists($guestfile)){
$filebuffer=file($guestfile);
if(sizeof($filebuffer)>100){
for($i=0;$i<100;$i++)
$newbuffer[i]=$filebuffer[i];
}
else{
$newbuffer=$filebuffer;
}
$fp=fopen($guestfile,"w");
fputs($fp,$adddata);
fclose($fp);
$buffer=implode("",$newbuffer);
$fp=fopen($guestfile,"a");
fputs($fp,$buffer);
fclose($fp);
}
else{
$fp=fopen($guestfile,"w");
fwrite($fp,$adddata);
fclose($fp);
}
}
?>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>留言板</title>
<style>
a{text-decoration:none; font-size:9pt; color:blue}
a:visited {text-decoration:none; color:009999}
a:hover {color:red; text-decoration:underline}
td{font-size:9pt;line-height:14pt}
P{font-size:9pt}
</style>
</head>
<?php
if($backimage!="" && file_exists($backimage)){
echo "<body background="".$backimage."" bgproperties="fixed">n";
}
else{
echo "<body bgcolor="".$backcolor."">n";
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="#9999FF">
<td height="28">
<div align="center"><b>供电9901网上空间留言板</b></div>
</td>
</tr>
<tr><td><div align="right"><a href="<? echo $home; ?>">[返回首页]</a></div></td></tr>
</table>
<font size="2">
<form method="post" action="guest.php">
<input type="hidden" name="mode" value="add">
<p>姓名:
<input type="text" name="name" size="20">
<br>
E_Mail:
<input type="text" name="e_mail" size="20">
<br>
主页:
<input type="text" name="url" value="http://" size="30">
<br>
留言标题:
<input type="text" name="title" size="50">
<br>
留言内容:(不支持HTML)<br>
<textarea name="data" rows="5" cols="60"></textarea>
<div id="Layer1" style="position:absolute; left:460px; top:152px; width:301px; height:104px; z-index:1">
<p>表情:</p>
<p>
<input type="radio" name="icon" value="1">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014115_b2f627fff19fda463cb386442eac2b3d.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="2">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014115_aba3b6fd5d186d28e06ff97135cade7f.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="3">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014115_1f4477bad7af3616c1f933a02bfabe4e.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="4" checked>
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014116_0266e33d3f546cb5436a10798e657d97.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="5">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014117_0353ab4cbed5beae847a7ff6e220b5cf.gif"; ?>" width="15" height="15">

<input type="radio" name="icon" value="6">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014117_5f0f5e5f33945135b874349cfbed4fb9.gif"; ?>" width="15" height="15"><br>
<input type="radio" name="icon" value="7">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014117_a532400ed62e772b9dc0b86f46e583ff.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="8">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014118_e1e32e235eee1f970470a3a6658dfdd5.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="9">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014118_6aab1270668d8cac7cef2566a1c5f569.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="10">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014119_8d6dc35e506fc23349dd10ee68dabb64.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="11">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014123_49c9adb18e44be0711a94e827042f630.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="12">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014123_8eefcfdf5990e441f0fb6f3fad709e21.gif"; ?>" width="15" height="15"><br>
<input type="radio" name="icon" value="13">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014124_a4f23670e1833f3fdb077ca70bbd5d66.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="14">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014124_2bb232c0b13c774965ef8558f0fbd615.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="15">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014124_e836d813fd184325132fca8edcdfb40e.gif"; ?>" width="15" height="15">
<input type="radio" name="icon" value="16">
<img src="<? echo $imagedir."/upload/tech/20091012/20091012014131_e44fea3bec53bcea3b7513ccef5857ac.gif"; ?>" width="15" height="15"> </p>
</div>
</p>
<p align="center">
<input type="submit" name="b1" value="写入">
<input type="reset" name="b2" value="重写">
</p>
</form>
<hr>
<?php
if(!file_exists($guestfile)){
echo "<p align="center">没有留言</p>";
}
else{
$filebuffer=file($guestfile);
$size=sizeof($filebuffer);
$pages=ceil($size/20);
echo "<p align="center">共".$size."条留言 第".$page."页/共".$pages."页<br>";
if($page>1){
$prev=$page-1;
echo "<a href="guest.php?".$prev.""><<</a> ";
}
for($i=1;$i<=$pages;$i++){
echo " <a href="guest.php?".$i."">".$i."</a> ";
}
if($page<$pages){
$next=$page+1;
echo "<a href="guest.php?".$next.""> >></a>";
}
echo "</p></font><table width="650" border="0" cellspacing="0" cellpadding="0">";
for($i=($page-1)*20; $i<$page*20 && $i<$size; $i++){
$buffer=explode("t",$filebuffer[$i]);
echo "<tr><td valign="top" width="25"><img src="".$imagedir."/".$buffer[5].".gif"></td>";
echo "<td valign="top" width="250"><p align="left">".$buffer[3]."</p></td>";
echo "<td valign="top" width="80"><p align="left"><B>(".$buffer[0].")</B></p></td>";
echo "<td valign="top" width="35"><p align="center">";
if($buffer[2]!="0"){
echo "<a href="".$buffer[2]."">主页</a>";
}
else{
echo "主页";
}
echo "</p></td>";
echo "<td valign="top" width="35"><p align="center">";
if($buffer[1]!="0"){
echo "<a href="mailto:".$buffer[1]."">E_Mail</a>";
}
else{
echo "E_Mail";
}
echo "</p></td>";
echo "<td valign="top" width="175"><p align="left">".$buffer[6]."</p></td>";
echo "</tr><tr><td> </td>";
echo "<td colspan="5" width="575">".$buffer[4]."</td></tr><tr><td> </td></tr>";
}
}
?>
</table><hr><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td>
<div align="center">本网站由<a href="mailto:[email protected]">疯狂电脑工作室</a>制作 2000</div></td></tr></table>
</body></html>
大家可到gd9901.oso.com.cn看看效果,有什么问题请E_Mail至[email protected]