ip address lookup location php script

This IP Geolocation PHP module allows user to find the IP geolocation information about an IP address such as country codes, country name, region, district, city, coordinates, ZIP code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, MCC, MNC, mobile brand name, elevation, usage type, address type, IAB category and ASN that any IP address or host name originates from. It has been optimized for speed and memory utilization. Developers can use our IP geolocation API to query all IP2Location™ binary databases for IPv4 and IPv6 address.

IP Address Location tracker full source code free download ?

As of my last knowledge update in January 2023, I don’t have specific information on the latest libraries or updates that may have been released after that date. For the most current and up-to-date information on IP address geolocation libraries, I recommend checking online resources, official documentation, and community forums.

As of my last update, MaxMind’s GeoIP2 library was a commonly used option. However, it’s important to note that services and libraries can evolve, and new options may become available. Always refer to the official documentation of the library you choose for the latest information.

To find the latest and most up-to-date IP geolocation libraries in 2023, you can:

  1. Check Online Repositories: Visit platforms like GitHub or PyPI and search for IP geolocation libraries. These platforms often host the latest versions of libraries, and you can find documentation and user reviews.
  2. Visit Official Websites: Go to the official websites of popular IP geolocation providers (such as MaxMind) to see if they have released any updates or new libraries.
  3. Community Forums: Participate in community forums related to geolocation, IP tracking, or relevant programming languages. Communities often share information about the latest tools and libraries.
  4. Developer Documentation: Always refer to the official documentation of any library you are interested in. It should provide details on the latest version, features, and any changes.

Keep in mind that the specific needs of your project may influence your choice of library, so it’s essential to review the documentation and features of each option to find the one that best fits your requirements

 

IP2Location IP Geolocation C library enables the user to find the country, region, city, coordinates, ZIP code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type that any IP address or hostname originates from.

 

{
  "ip": "103.175.8.40",
  "city": "Jaipur",
  "region": "Rajasthan",
  "regioncode": "RJ",
  "country": "India",
  "countrycode": "IN",
  "postalcode": "302022",
  "loc": "26.9525,75.7105",
  "time_zone": "Asia/Kolkata",
  "org": "Spiderlink Networks Pvt Ltd",
  "continentcode": "AS",
  "continentname": "Asia",
  "browser": "Chrome",
  "osname": "Windows 10"
}

 

Full Source Code Download Link :  Click Here

 

Download IP Info Library

 

To install the geoip2/geoip2 library using Composer, you can use the following command:

composer require geoip2/geoip2

Simply run this command in your terminal or command prompt in the root directory of your PHP project, and Composer will automatically download and install the geoip2/geoip2 library along with its dependencies.

After running the command, Composer will create or update your composer.json file and install the necessary files in the vendor directory of your project. You can then include the Composer autoloader in your PHP code to use the library:

<?php

require 'vendor/autoload.php';

use GeoIp2\Database\Reader;

$reader = new Reader('path/to/GeoLite2-City.mmdb');

$ipAddress = '8.8.8.8';

try {
$record = $reader->city($ipAddress);
echo 'City: ' . $record->city->name . "\n";
echo 'Country: ' . $record->country->name . "\n";
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage() . "\n";
}

Make sure to replace 'path/to/GeoLite2-City.mmdb' with the actual path to your GeoLite2 City database file.

If you haven’t installed Composer globally, you might need to use php composer.phar require geoip2/geoip2 instead. Ensure that the Composer executable (composer or composer.phar) is in your system’s PATH.

Create ipinfo.php files


<?php require 'geoip2/autoload.php'; use MaxMind\Db\Reader; // Path to the GeoIP2 City database file $databasePath = 'geoip2/GeoLite2-City.mmdb'; if($_REQUEST['ip']){ $clientIp = $_REQUEST['ip']; }else{ // Get client's IP address if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $clientIp = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $clientIp = $_SERVER['REMOTE_ADDR']; } } // Create a reader for the GeoIP2 City database $reader = new Reader($databasePath); $databasePath2 = 'geoip2/GeoLite2-ASN.mmdb'; $reader2 = new Reader($databasePath2); $record2 = $reader2->get($clientIp);

// Look up the location information for the IP address
$record = $reader->get($clientIp);

// Display the location information

function get_user_os() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];

    $os_platform  = "Unknown OS Platform";

    $os_array = array(
        '/windows nt 10/i'      =>  'Windows 10',
        '/windows nt 6.3/i'     =>  'Windows 8.1',
        '/windows nt 6.2/i'     =>  'Windows 8',
        '/windows nt 6.1/i'     =>  'Windows 7',
        '/windows nt 6.0/i'     =>  'Windows Vista',
        '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
        '/windows nt 5.1/i'     =>  'Windows XP',
        '/windows xp/i'         =>  'Windows XP',
        '/windows nt 5.0/i'     =>  'Windows 2000',
        '/windows me/i'         =>  'Windows ME',
        '/win98/i'              =>  'Windows 98',
        '/win95/i'              =>  'Windows 95',
        '/win16/i'              =>  'Windows 3.11',
        '/macintosh|mac os x/i' =>  'Mac OS X',
        '/mac_powerpc/i'        =>  'Mac OS 9',
        '/linux/i'              =>  'Linux',
        '/ubuntu/i'             =>  'Ubuntu',
        '/iphone/i'             =>  'iPhone',
        '/ipod/i'               =>  'iPod',
        '/ipad/i'               =>  'iPad',
        '/android/i'            =>  'Android',
        '/blackberry/i'         =>  'BlackBerry',
        '/webos/i'              =>  'Mobile'
    );

    foreach ($os_array as $regex => $value) {
        if (preg_match($regex, $user_agent)) {
            $os_platform = $value;
        }
    }

    return $os_platform;
}

$user_os = get_user_os();



function get_user_browser() {
    $user_agent = $_SERVER['HTTP_USER_AGENT'];

    $browser = "Unknown Browser";

    $browser_array = array(
        '/msie/i'      => 'Internet Explorer',
        '/firefox/i'   => 'Firefox',
        '/safari/i'    => 'Safari',
        '/chrome/i'    => 'Chrome',
        '/edge/i'      => 'Edge',
        '/opera/i'     => 'Opera',
        '/netscape/i'  => 'Netscape',
        '/maxthon/i'   => 'Maxthon',
        '/konqueror/i' => 'Konqueror',
        '/mobile/i'    => 'Handheld Browser'
    );

    foreach ($browser_array as $regex => $value) {
        if (preg_match($regex, $user_agent)) {
            $browser = $value;
        }
    }

    return $browser;
}

$user_browser = get_user_browser();

    $url = "https://ipinfo.io/$clientIp/json";
    $response = file_get_contents($url);
    $data = json_decode($response, true);
    
 if($record['city']['names']['en']==false){
     $ipinfo = '{
  "ip": "'.$clientIp.'",
  "city": "'.$data['city'].'",
  "region": "'.$data['region'].'",
  "countrycode": "'.$data['country'].'",
  "postalcode": "'.$data['postal'].'",
  "loc": "'.$data['loc'].'",
  "time_zone": "'.$data['timezone'].'",
  "org": "'.$data['org'].'",
  "browser": "'.$user_browser.'",
  "osname": "'.$user_os.'"
}';
 }else{   

$ipinfo = '{
  "ip": "'.$clientIp.'",
  "city": "'.$record['city']['names']['en'].'",
  "region": "'.$record['subdivisions'][0]['names']['en'].'",
  "regioncode": "'.$record['subdivisions'][0]['iso_code'].'",
  "country": "'.$record['country']['names']['en'].'",
  "countrycode": "'.$record['country']['iso_code'].'",
  "postalcode": "'.$record['postal']['code'].'",
  "loc": "'.$record['location']['latitude'].','. $record['location']['longitude'].'",
  "time_zone": "'.$record['location']['time_zone'].'",
  "org": "'.$record2['autonomous_system_organization'].'",
  "continentcode": "'.$record['continent']['code'].'",
  "continentname": "'.$record['continent']['names']['en'].'",
  "browser": "'.$user_browser.'",
  "osname": "'.$user_os.'"
}';
}
print_r($ipinfo);

// Close the GeoIP2 reader
$reader->close();

 

Leave a Reply

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