Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get country from ip php

<?php
/**
 * For my company in particular the below HTTP_CF_IPCOUNTRY
 * didn't work and there was need to call an API that was in HTTPS
 * and that didn't use any key to access the country ISO2 info.
 */
$userIp = $_SERVER['REMOTE_ADDR'];
$ipLocationObj = json_decode(file_get_contents(
  "https://api.iplocation.net/?ip={$userIp}"
));
$userCountryISO = $ipLocationObj->country_code2 ?? "";
/** ipLocationObj will be an object like this one:
{
	"ip":"xxx.xxx.xxx.xxx",
    "ip_number":"0123456789",
    "ip_version":4,
    "country_name":"Italy",
    "country_code2":"IT",
    "isp":"Wind Telecomunicazioni S.P.A",
    "response_code":"200",
    "response_message":"OK"
}
*/
Comment

php get IP country

$_SERVER["HTTP_CF_IPCOUNTRY"];
Comment

PREVIOUS NEXT
Code Example
Php :: php convert string to int in array 
Php :: laravel get timezone from ip address 
Php :: php move file to another directory 
Php :: laravel 4.2 migration 
Php :: get parameter php 
Php :: read pdf text in php 
Php :: php string underscore into camelcase 
Php :: php get keys and values from array 
Php :: php previous page 
Php :: download laravel 8 zip 
Php :: upload file in php 
Php :: get month from database php 
Php :: get app url in laravel 
Php :: Laravel 5.4 Route back in blade 
Php :: php link to page 
Php :: wordpress exclude current post from loop 
Php :: migrate particular file laravel 
Php :: php end session 
Php :: create function php 
Php :: implode and explode in php 
Php :: laravel redirect url 
Php :: laravel custom log 
Php :: laravel online hash password generator 
Php :: fetch data from live website curl php 
Php :: laravel composite unique key 
Php :: laravel validation date 
Php :: php check if entire array are in another array 
Php :: how to insert date in mysql using php 
Php :: upload_max_filesize in wordpress 
Php :: report simple error in php 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =