PHP code example of pta / ipinfo

1. Go to this page and download the library: Download pta/ipinfo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pta / ipinfo example snippets


// Create a new instance
$ipInfo = new ipInfo (APIKEY, 'json');

// Grab the user location info
$location = json_decode($ipInfo->getCountry($userIP));

// Create a cookie holding the country code for 1 hour (3600 seconds)
setcookie('location', $location['countryCode'], time() + 3600);