Page 1 of 1

geo-ip

Posted: Mon Oct 20, 2014 9:25 pm
by Vegan
found this while researching some for new functionality for my web sites

http://php.net/manual/en/book.geoip.php

what I was looking to do is recognize certain markets and tweak ads for location aware

Code: Select all

string geoip_country_code_by_name ( string $hostname )
I have code now to supply hostname from a page I made earlier

Code: Select all

<?php 
echo ' Client IP address: '; 
if ( isset($_SERVER["REMOTE_ADDR"]) )    { 
    echo '' . $_SERVER["REMOTE_ADDR"] . ' '; 
} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    { 
    echo '' . $_SERVER["HTTP_X_FORWARDED_FOR"] . ' '; 
} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    { 
    echo '' . $_SERVER["HTTP_CLIENT_IP"] . ' '; 
} 
?>

Re: geo-ip

Posted: Sat Aug 07, 2021 2:01 am
by kiash
You can use cloudflare to get geo ip location. it is very fast and pretty correct.

Code: Select all

$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];