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

所属分类: 网络编程 / PHP编程 阅读数: 1762
收藏 0 赞 0 分享
小弟初学PHP,编了一个留言板程序,自我感觉良好,故厚着脸皮放了上来,请各位大哥指正。源程序如下: 
<?php 
//文件名:guest.php 
//设定部分 
$guestfile="guest";//纪录留言的文本文件 
$home="index.html";//返回的主页 
$imagedir="image"; //图像文件的目录 
$backimage=$imagedir."/bk.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(" ","&nbsp;",$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."/1.gif"; ?>" width="15" height="15"> 
      <input type="radio" name="icon" value="2"> 
      <img src="<? echo $imagedir."/2.gif"; ?>" width="15" height="15"> 
      <input type="radio" name="icon" value="3"> 
      <img src="<? echo $imagedir."/3.gif"; ?>" width="15" height="15"> 
      <input type="radio" name="icon" value="4" checked> 
      <img src="<? echo $imagedir."/4.gif"; ?>" width="15" height="15"> 
      <input type="radio" name="icon" value="5"> 
      <img src="<? echo $imagedir."/5.gif"; ?>" width="15" height="15">
更多精彩内容其他人还在看

两种php去除二维数组的重复项方法

这篇文章主要介绍了两种php去除二维数组的重复项方法,大家可以进行比较看哪一种更适合自己,需要的朋友可以参考下
收藏 0 赞 0 分享

php实现分页功能的3种方法第1/3页

这篇文章主要介绍了php实现分页功能的3种方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php对二维数组进行相关操作(排序、转换、去空白等)

这篇文章主要介绍了php对二维数组进行相关操作,包括php对二维数组排序、转换、去空白,以及去重复值等,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php实现网站留言板功能

这篇文章主要介绍了php实现网站留言板功能,主要仿照了畅言留言板和网易跟帖样式进行制作,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

PHP实现HTML页面静态化的方法

这篇文章主要介绍了PHP实现HTML页面静态化的方法,分享了静态处理的方法,静态处理后的优势,并提供了多种静态的方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php对文件夹进行相关操作(遍历、计算大小)

这篇文章主要介绍了php对文件夹进行相关操作,包括遍历并打印指定目录下所有文件和计算文件大小去空白,以及去重复值等,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

非常全面的php日期时间运算汇总

这篇文章主要整理了关于php日期时间运算相关内容,涉及知识点较为全面,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php根据用户语言跳转相应网页

这篇文章主要介绍了php根据用户语言跳转相应网页的方法,主要区分国内国外,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

双冒号 ::在PHP中的使用情况

前几天在百度知道里面看到有人问PHP中双冒号::的用法,当时给他的回答比较简洁因为手机打字不大方便!今天突然想起来,所以在这里总结一下我遇到的双冒号::在PHP中使用的情况
收藏 0 赞 0 分享

PHP explode()函数的几个应用和implode()函数有什么区别

这篇文章主要介绍了PHP explode()函数的几个应用和implode()函数有什么区别,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多