1

我想保留访问者的 ips 并将它们放在一个文件中。
我尝试了 fwrite() 函数,但我认为它是在文件上的 previus ip 上重写。

例子。

ip.txt 为空。

当我运行 write.php 脚本时,在 ip.txt 我有 xxxx ip(我的 ip)

如果我的朋友运行 write.php 脚本,在 ip.txt 我有 aaaa ip(仅限朋友的 ip)

我的ip在哪里?我想在 ip.txt 文件上有以下内容:

x.x.x.x   ip1  
a.a.a.a   ip2

write.php 上的代码如下。

<?php
$file = fopen("ip.txt","w");
$ip=$_SERVER['REMOTE_ADDR'];
echo fwrite($file,$ip);
fclose($file);
?> 
4

3 回答 3

6

将“w”更改为“a”

W 表示写入(over),a 表示追加。

于 2012-12-30T02:30:32.953 回答
1
<?php
$file = fopen("ip.txt","a");
$ip=$_SERVER['REMOTE_ADDR'];
echo fwrite($file,$ip);
fclose($file);
?> 

说明书

检查第二个参数的含义。

您选择w了覆盖模式。改为尝试a模式(附加)

于 2012-12-30T02:33:15.153 回答
1

数据库版本的“优点”是没有人可以查看数据。如果需要,您可以使用 .htaccess 文件避免访问该文件:

对于 Apache 2.2

# Protect log.txt
<Files ./inscription/log.txt>
Order Allow,Deny
Deny from all
</Files>

对于 Apache 2.4

# Protect log.txt
<Files ./inscription/log.txt>
Require all denied
</Files>
于 2017-06-22T18:57:39.483 回答