简体   繁体   中英

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. Also, every time a new user opens my website, the value of ip gets changed. 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. Any help regarding this would be highly appreciated.

This will work for you. You must have a PHP-enabled server for this to work. The ip.txt data file will create itself, and it will appear in the same folder as the page it is included in.
Put this in the top of your website PHP file..

<?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.

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. I hope you find this of use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM