仿网易163新闻评论盖楼效果代码
//发送留言
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("n","
",$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 "<script>location.href="index.php?page=$page"</script>";
exit;
}
?>
ini_set("display_errors",0);
require("global.func.php");
?>
显示像163评论
";";
$__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);
}
/**
*写入文件
*@param string $filename
*@param string $contents
*@return 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;
}
}
/**
*读取文件
*@param string $filename
*@return $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' => 'php100.com',
'id' => 1,
'date' => 1253853347,
'fid' => 0,
'ip' => '116.226.2.200',
),
1 =>
array (
'username' => 'aaaaaaaaaaad',
'content' => 'www.bkjia.com',
'id' => 2,
'date' => 1253857672,
'fid' => 0,
'ip' => '116.226.6.188',
),
)?>