is it possible to write the IP and Location of the visitor in a file? this is my code:
<?php $line = date('Y-m-d H:i:s') . " - $_SERVER[REMOTE_ADDR]"; file_put_contents('visitors.log', $line . PHP_EOL, FILE_APPEND); ?>
But its only writing the IP down.
Now i have this code for Javascript (but this is only GET location and ip and yes i know im noob):
<script> $.get("http://ipinfo.io", function (response) {
$("#ip").html("IP: " + response.ip);
$("#address").html("Location: " + response.city + ", " + response.region);
$("#details").html(JSON.stringify(response, null, 4)); }, "jsonp");</script>
Is it possible to put that in a file? Thank you in advanced.
You've to send the data you received with the help of ajax to server. Then at server, set up PHP script to receive data and then store it as a file. You can't do it directly with javascript because of security purposes (javascript doesn't allow file editing).
JS:
$.ajax({
type:"GET",
url:"script.php",
data : { ip: myIP, location : myLocation },
.....
});
PHP:
<?php
$ip = $_GET['ip'];
$location = $_GET['location'];
// File handling...
?>