给一段代码给你看看
$file="../data/".$fromid.".txt";
if(!file_exists($file)){
$fw=fopen($file,"w");
fclose($fw);
}
$newtime=time();
$check=0;
$ipcf=1;
$fp=fopen($file,"r");
flock($fp,3);
$data=file($file);
$co=count($data);
$open=fopen($file,"w+");
flock($open,3);
for($i=0; $i<$co; $i++)
{
$new=explode("|",$data[$i]);
$time=$newtime-$new[1];
if ($new[0]==$REMOTE_ADDR)
{
$ipnum=$new[2]+1;
fputs($open,"$REMOTE_ADDR|$newtime|".$ipnum."\n");
$check++;
if ($ipnum>$ipcf)$ipcf=$ipnum;
}
elseif ($time < $mastime)
{
fputs($open,"$data[$i]");
}
}
if ($check==0)
{
fwrite($open,"$REMOTE_ADDR|$newtime|1\n");
fclose($open);
}
else
{
if ($ipcf>15 or $check>=4 or ($check==3 and $ipcf>2) or ($check==2 and $ipcf>4))
{
$qu=mysql_query("update user_web set is_lock='true',lock_cause='网站作鄙' where id=$fromid");
}
exit;
}
$file="../data/".$fromid.".txt";
if(!file_exists($file)){
$fw=fopen($file,"w");
fclose($fw);
}
$newtime=time();
$check=0;
$ipcf=1;
$fp=fopen($file,"r");
flock($fp,3);
$data=file($file);
$co=count($data);
$open=fopen($file,"w+");
flock($open,3);
for($i=0; $i<$co; $i++)
{
$new=explode("|",$data[$i]);
$time=$newtime-$new[1];
if ($new[0]==$REMOTE_ADDR)
{
$ipnum=$new[2]+1;
fputs($open,"$REMOTE_ADDR|$newtime|".$ipnum."\n");
$check++;
if ($ipnum>$ipcf)$ipcf=$ipnum;
}
elseif ($time < $mastime)
{
fputs($open,"$data[$i]");
}
}
if ($check==0)
{
fwrite($open,"$REMOTE_ADDR|$newtime|1\n");
fclose($open);
}
else
{
if ($ipcf>15 or $check>=4 or ($check==3 and $ipcf>2) or ($check==2 and $ipcf>4))
{
$qu=mysql_query("update user_web set is_lock='true',lock_cause='网站作鄙' where id=$fromid");
}
exit;
}
// 写文件
$fp = fopen($filename,"w");
fwrite($fp,$title."\n".$content); // 写入标题和内容,第一行为标题
fclose($fp);// 读文件
$fp = fopen($filename,"r");
$title = fgets($fp,2048); // 读回标题
$content = fread($fp,filesize($filename)); // 读回内容
fclose($fp);
$x=1;
$bk="book".$x.".txt";
while(file_exists($bk))
{$x++;$bk="book".$x.".txt";}//寻找最后生成的文件
$x--;$bk="book".$x.".txt";
$fo = fopen($bk,"r"); //打开最新文件并读入
$print = fread($fo,filesize($bk));
fclose($fo);
print "$print";
$page=fopen("page.txt","w"); //写入当前文件号
fwrite($page,$x);
fclose($page);
}
else //当选择页面时
{
$page=fopen("page.txt","r");
$x=fread($page,filesize("page.txt"));
fclose($page); if($pgselect=="pre"&& $x>1) $x-=1;//选前一页限制到第1页为止
else if($pgselect=="next") $x+=1;//选后一页时增加1
else if($pgselect=="start") $x=1;//选第1页 $bk="book".$x.".txt";
if(!file_exists($bk))$x--;//如文件不存在则减少页号1
$bk="book".$x.".txt"; $fo = fopen($bk,"r");
$print = fread($fo,filesize($bk));
fclose($fo);
print "$print";
$page=fopen("page.txt","w");//写入当前页号
fwrite($page,$x);
fclose($page);
}
?>