2
I’m using the code below, but only writes "::1" to the file.
<?php
$arquivo = "ips.txt";
$file = fopen($arquivo,"a");
$string = $_SERVER['REMOTE_ADDR'] . "\n";
$fp = fwrite($file,$string);
fclose($file);
?>
Is it because I’m on localhost?
2
I’m using the code below, but only writes "::1" to the file.
<?php
$arquivo = "ips.txt";
$file = fopen($arquivo,"a");
$string = $_SERVER['REMOTE_ADDR'] . "\n";
$fp = fwrite($file,$string);
fclose($file);
?>
Is it because I’m on localhost?
3
using the code placed in question ... I just remembered this way...
<?php
$arquivo = "ips.txt";
$string = $_SERVER['REMOTE_ADDR'] . "\n";
// ao usar FILE_APPEND para adicionar ao ficheiro estamos a colocar no fim do mesmo
// e com o LOCK_EX trata das gravações concurrentes que podem acontecer
file_put_contents($arquivo, $string, FILE_APPEND | LOCK_EX);
?>
::1 is the notation Ipv6 for 127.0.0.1
I tested it on a free host and the codes and work. I followed your answer, but every time I update the page the same ip is recorded again. How to record only if you’re not already there?
I recommend the use of a database. Otherwise you will have to read the file and search for its IP, clearly a worse solution.
I’ll do it myself, but I need to know how to work files for other things.
How I would read?
Browser other questions tagged php filing-cabinet text-editor ip
You are not signed in. Login or sign up in order to post.
Depending on your server’s settings it may even be. It may seem silly, but echo $_SERVER['REMOTE_ADDR'] returns the same thing?
– Bruno Augusto
You can test if you have another device on the network. It can even be your cell phone. Enter the page you are doing and make an echo as Bruno said.
– Oralista de Sistemas
Yes, returns "::1" as well.
– I Wanna Know
::1 is the localhost Ipv6
– Tony
Have you considered using http://www.google.com/intl/pt-BR_ALL/analytics/
– Alex Schmitt
@Alexschmitt I know, but right now I need that knowledge.
– I Wanna Know
I tested on a free host the code and it works. I followed @chambelix’s reply, but every time I update the page the same ip is recorded again. How to record only if you’re not already there?
– I Wanna Know
If the user is using proxy, you would have to match some checks with,
HTTP_CLIENT_IP
,HTTP_X_FORWARDED_FOR
, however, they can be easily manipulated whileREMOTE_ADDR
cannot. Take into account that some programs provide a new IP for "anonymous" browsing, and in this case the IP nay would be the real IP of the user even usingREMOTE_ADDR
.– Papa Charlie
Truth, for question of identification is uncertain, however for statistical purposes should serve.
– I Wanna Know