简体   繁体   English

我该如何存储访问我网站的最近100个IP地址?

[英]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.

相关问题 我可以告诉在我的网站之前有人访问过的最后一个网站吗? - Can I tell the last website someone visited before my site? 如何创建Cookie以将5个最近访问的网页存储在我的域中? - How to create a cookie to store the 5 last visited web pages in my domain? 我能否检测我的 PWA 是作为应用程序启动还是作为网站访问? - Can I detect if my PWA is launched as an app or visited as a website? 如何在我的网站上存储永久变量? - How can I store a permanent variable on my website? 如何使用JavaScript对BIRT上的IP地址进行排序? - How can I sort ip addresses on BIRT with JavaScript? 根据上次访问的网站进行重定向 - Redirect based on last visited website 如何获取将访问者连接到我的网站的IP地址/位置,并向我显示他们的地址? - How to get IP address / location of connecting visitors to my website, and show THEIR addresses to me? 我想仅通过选定的IP地址访问网站上的内容吗? - I want the content on a website to be accessed by only selected ip addresses? 如何让我的机器人找到符合条件的最后一条消息,ex(“joe”)并发送给发送者? - How can I make my bot find the last message that matches a criteria, e.x ("joe") and send who sent it? 在iOS上的网站上键入密码时,如何隐藏最后一位数字 - How can I hide the last digit when I'm typing a password on my website on iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM