geo-ip

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

geo-ip

Post 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"] . ' '; 
} 
?>
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
kiash
Forum Newbie
Posts: 7
Joined: Sat Aug 07, 2021 1:42 am
Contact:

Re: geo-ip

Post 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"];
I am a full stack developer. My persoal site Kiash.io and I work for Slide.pub as a lead developer.
Post Reply