Translate this page

PHP: Get Visitors IP and Location and Save to TXT File

How to get visitors IP address and Location and save them to Text file in php

This simple php code can be used to save visitors data such as location, IP address etc and log them to a text file.

$ip = $_SERVER['REMOTE_ADDR']; //get supposed IP
$query = @unserialize(file_get_contents(''.$ip));
$handle = fopen("data.txt", "a"); //open log file
fwrite($handle, "IP: $ip \r\n");
if($query && $query['status'] == 'success') {
$hh = $query['country'].', '.$query['city'].'!';
fwrite($handle, "Location: $hh \r\n \r\n");

} else {
  fwrite($handle, "Location: Unavailable \r\n \r\n");





Related Posts

How to create a Database in MYSQL using PHP

Creating a database in MySQL using PHP is a common task that many web developers need to do. A database is a collection of data that is…

silver imac displaying collage photos

Fix PHP Unable to find the wrapper “https” – did you forget to enable it when you configured PHP?

Here is how to fix Unable to find the wrapper “https” problem in PHP In php development, you will encounter this error when trying to access an…

Leave a Reply

Your email address will not be published. Required fields are marked *