[英]how can i store last 100 ip addresses who visited my website?
i have a variable say 'ip' which displays the current ip of a visitor who visits my website. 我有一个变量说“ ip”,它显示访问我的网站的访问者的当前ip。 Also, every time a new user opens my website, the value of ip gets changed.
另外,每次有新用户打开我的网站时,ip的值都会更改。 i need to store first 100 ip addresses who visits my website in an array containing 100 elements so that i can use them for comparison later on using java script.
我需要将访问我的网站的前100个IP地址存储在包含100个元素的数组中,以便以后在使用Java脚本时可以使用它们进行比较。 Any help regarding this would be highly appreciated.
任何帮助对此将不胜感激。
This will work for you. 这将为您工作。 You must have a
PHP-enabled
server for this to work. 您必须具有
PHP-enabled
服务器才能运行此服务器。 The ip.txt
data file will create itself, and it will appear in the same folder as the page it is included in. ip.txt
数据文件将自行创建,并显示在与其所在页面相同的文件夹中。
Put this in the top of your website PHP file.. 将其放在网站PHP文件的顶部。
<?php
$file = "./ip.txt";
$date = date("Y-m-d H:i:s");
$ip = $_SERVER["REMOTE_ADDR"];
$write = "Date = ".$date." :>IP = ".$ip."|";
file_put_contents($file, $write, FILE_APPEND);
?>
This is the page to read the IP and date, or you could simply open it with a text editor. 这是读取IP和日期的页面,或者您可以简单地使用文本编辑器将其打开。
The read_ip.php file...
<?php
$read_ip = './ip.txt';
$doc = file_get_contents($read_ip);
$ip_data = explode("|",$doc);
$i = 0;
foreach($ip_data as $data){
$i++;
echo 'row '.$i.':> '.$data.'<br />';
}
?>
Simple and straightforward. 简单明了。 MySql or any other database system is not required... the .TXT file IS your database.
不需要MySql或任何其他数据库系统... .TXT文件是您的数据库。 I hope you find this of use.
希望您能找到用处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.