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 check if its a name 
Php :: php mysqli number row 
Php :: how change the languge of fie manager in laravel 
Php :: restcord Guild Icon outputs 404. 
Php :: phpmailer for wordpress 
Php :: display summernonte data with string limit laravel 
Php :: laravel migrate only one table 
Php :: laravel with trashed 
Php :: php header excel utf-8 
Php :: php get intersection of arrays 
Php :: show date time with milliseconds php 
Php :: get current page php 
Php :: add new column to table laravel 
Php :: route group controller laravel 
Php :: select sum in laravel 
Php :: php get file type from url 
Php :: php redirect after specific seconds 
Php :: laravel migrate fresh 
Php :: php preg_replace whitespace 
Php :: tcpdf error unable to create output file in php 
Php :: php sessions 
Php :: get single row in codeigniter 
Php :: truncate table laravel eloquent 
Php :: fix excel file wrong language php 
Php :: create new laravel project cmd 
Php :: laravel mongodb delete 
Php :: wp-admin redirecting to the https wordpress 
Php :: php put print_r into variable 
Php :: get only date in laravel 
Php :: laravel where condition on relationship 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =