//发送留言
require("global.func.php教程");
$fid=isset($_GET["id"])?intval($_GET["id"]):0;
$page=isset($_GET["page"])?intval($_GET["page"]):1;
if($_SERVER["REQUEST_METHOD"]=="POST")
{
 if(!file_exists("1.php"))
 {
  writeFile("1.php",$array=array());
 }
 $arr=require("1.php");
 $post=array();
 unset($_POST["Submit"]);
 foreach($_POST as $k=>$v)
 {
  $post[$k]=addslashes(htmlspecialchars($v));
 }
 $post["content"]=str_replace(" ","
",$post["content"]);
 $post["id"]=count($arr)+1;
 $post["date"]=time();
 $post["fid"]=$fid;
 $post["ip"]=$_SERVER["REMOTE_ADDR"];
 $arr[]=$post;
 writeFile("1.php",$arr);
 
 echo "";
 exit;
}
?>
ini_set("display_errors",0);
require("global.func.php");
?>
显示像163评论
http://www.*w**3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
https://www.111cn.net/1999/xhtml">
";";
$__str.=$v["ip"]."用户:".$v["username"]."内容:".$v["content"]."";
showChild($v["id"]);
$__str.="
function showChild($id,$i=0)
{
 global $__array,$__str,$page,$offset;
 
 
 if($i==15)//递归层数
 {
  return;
 }
 $i++;
 foreach($__array as $k=>$v)
 {
  if($v["fid"]==$id)
  {
   $__str.= "
";";
$__str.= $__array[$k]["ip"]."用户:".$__array[$k]["username"]."内容:".$__array[$k]["content"]."";
showChild($v["id"],$i);
$__str.= "
show($fid0,$pagesize,$offset);
$total=getTotal();
echo $__str;
pageft($total,$pagesize,"index.php");
echo "
".$pagenav;
?>
global.func.php文件代码如下
function writeFile($id,$array)
{
 $content="";
 return safe_file_put_contents($id,$content);
}
/**
*写入文件
 string $filename
 string $contents
 boolean
*/
function safe_file_put_contents($filename,&$contents)
{
 $fp=fopen($filename,"wb");
 if($fp)
 {
  flock($fp,LOCK_EX);
  fwrite($fp,$contents);
  flock($fp,LOCK_UN);
  fclose($fp);
  return true;
 }else
 {
  return false;
 }
}
/**
*读取文件
 string $filename
 $data|false
*/
function safe_file_get_contents($filename)
{
 $fp=fopen($filename,"rb");
 if($fp)
 {
  flock($fp,LOCK_SH);
  clearstatcache();
  $filesize=filesize($filename);
  if($filesize>0)
  {
   $data=fread($fp,$filesize);
  }else
  {
   $data=false;
  }
  flock($fp,LOCK_UN);
  fclose($fp);
  return $data;
 }else
 {
  return false;
 }
}
function pageft($total,$displaypg=10,$url=''){
global $page,$firstcount,$pagenav,$_SERVER;
$GLOBALS["displaypg"]=$displaypg;
if(!$page) $page=1;
if(!$url){ $url=$_SERVER["REQUEST_URI"];}
$parse_url=parse_url($url);
@$url_query=$parse_url["query"]; 
if($url_query){
$url_query=ereg_replace("(^|&)page=$page","",$url_query);
$url=str_replace($parse_url["query"],$url_query,$url);
if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}
$lastpg=ceil($total/$displaypg); 
$page=min($lastpg,$page);
$prepg=$page-1; 
$nextpg=($page==$lastpg ? 0 : $page+1); 
if(!$page) $page=1;
$firstcount=($page-1)*$displaypg;
$pagenav.="  ";
if($prepg) $pagenav.="  "; else $pagenav.="上页 ";
if($nextpg) $pagenav.="  "; else $pagenav.="下页 ";
$pagenav.=" ";
$pagenav.=" 到  页";
}
?>
//保存的1.php文件数数组形式,如下格式
  0 => 
  array (
    'username' => 'test',
    'content' => '111com.net',
    'id' => 1,
    'date' => 1253853347,
    'fid' => 0,
    'ip' => '116.226.2.200',
  ),
  1 => 
  array (
    'username' => 'aaaaaaaaaaad',
    'content' => 'www.111com.net',
    'id' => 2,
    'date' => 1253857672,
    'fid' => 0,
    'ip' => '116.226.6.188',
  ),
  
)?>