如何用php程序记录来访IP
展开全部
有一个全局的变量,$_SERVER[RMOTE_ADDR]可以获取,
然后只要写到文件里就可以了
1 <pre>
2 <?php
3 $fp = fopen('iprecord.txt','ar+');
4 $i = 1;
5 if(filesize('./iprecord.txt') > 0)
6 {
7 $t = array();
8 $content = fread($fp,filesize('./iprecord.txt'));
9 $t = split("\n",$content);
10 $i = sizeof($t);
11 }
12 $record = $i.' ip: '.$_SERVER['REMOTE_ADDR']."\n";
13 fwrite($fp,$record);
14 fclose($fp);
15 ?>
16 </pre>
然后只要写到文件里就可以了
1 <pre>
2 <?php
3 $fp = fopen('iprecord.txt','ar+');
4 $i = 1;
5 if(filesize('./iprecord.txt') > 0)
6 {
7 $t = array();
8 $content = fread($fp,filesize('./iprecord.txt'));
9 $t = split("\n",$content);
10 $i = sizeof($t);
11 }
12 $record = $i.' ip: '.$_SERVER['REMOTE_ADDR']."\n";
13 fwrite($fp,$record);
14 fclose($fp);
15 ?>
16 </pre>
展开全部
有一个全局的变量,$_SERVER[RMOTE_ADDR]可以获取,
然后只要写到文件里就可以了
1 <pre>
2 <?php
3 $fp = fopen('iprecord.txt','ar+');
4 $i = 1;
5 if(filesize('./iprecord.txt') > 0)
6 {
7 $t = array();
8 $content = fread($fp,filesize('./iprecord.txt'));
9 $t = split("\n",$content);
10 $i = sizeof($t);
11 }
12 $record = $i.' ip: '.$_SERVER['REMOTE_ADDR']."\n";
13 fwrite($fp,$record);
14 fclose($fp);
15 ?>
16 </pre>
引楼上的
最好写数据库里面 然后再用 array_unique()函数移除重复的ip
然后只要写到文件里就可以了
1 <pre>
2 <?php
3 $fp = fopen('iprecord.txt','ar+');
4 $i = 1;
5 if(filesize('./iprecord.txt') > 0)
6 {
7 $t = array();
8 $content = fread($fp,filesize('./iprecord.txt'));
9 $t = split("\n",$content);
10 $i = sizeof($t);
11 }
12 $record = $i.' ip: '.$_SERVER['REMOTE_ADDR']."\n";
13 fwrite($fp,$record);
14 fclose($fp);
15 ?>
16 </pre>
引楼上的
最好写数据库里面 然后再用 array_unique()函数移除重复的ip
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
$ips_filename = "ipdata.txt;
$ipfiles = @file($ips_filename);
$num = count($ipfiles);
if($num >= 30){
$nbs = $num - 30 ;
for($j = 0;$j<30;$j++){
$data[] = $ipfiles[$nbs+$j];
}
}
else $data = $ipfiles;
$data[] = $_SERVER["REMOTE_ADDR"];
$data2str = implode("",$data);
@unlink($ips_filename);
file_put_contents($ips_filename,$data2str);
?>
$ips_filename = "ipdata.txt;
$ipfiles = @file($ips_filename);
$num = count($ipfiles);
if($num >= 30){
$nbs = $num - 30 ;
for($j = 0;$j<30;$j++){
$data[] = $ipfiles[$nbs+$j];
}
}
else $data = $ipfiles;
$data[] = $_SERVER["REMOTE_ADDR"];
$data2str = implode("",$data);
@unlink($ips_filename);
file_put_contents($ips_filename,$data2str);
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询