Internet advertising - Reference And Education Articles - Internet Advertising - Debt Consolidation - ID badge templates

PDA

View Full Version : How do I know which country my visitor is from?


hexadesigns
Sep 7th 2008, 3:44 am
Hi,

I want to display the selling price of my product, according to
the user's country. For example,

USA/Canada - USD
Europe - Euro
UK - GBP
Australia - AUD

and so forth, any ideas how this can be achieved with php? :)

dfourss
Sep 7th 2008, 4:01 am
the visitor's ip address should tell you where they are from

JAY6390
Sep 7th 2008, 4:19 am
use
$countries = array(
'uk' => 'GBP',
'us' => 'USD',
'com' => USD,
'au' => 'AUD');

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
preg_match('/\.([^\.]+)$/',$hostname,$out);
$tld = $out[1];

echo $countries[$tld];That should work for the majority, although it's not an exact science. Add the tld to the countries list along with the currency type (you can extend the array to hold different info too, this was just an example)

ammoun
Sep 7th 2008, 4:29 am
I think he might need a IP adresses database? :D

hexadesigns
Sep 7th 2008, 4:33 am
Thanks Jay6390, but i believe I am looking for what ammoun said. I need exact location based on the visitor's IP. Is this something that is quite complex or some readymade solutions are available?

JAY6390
Sep 7th 2008, 4:36 am
What about something like this
http://www.hotscripts.com/Detailed/54660.html

In fact, I think what you would be better using is
http://www.hostip.info/use.html

ilook
Sep 7th 2008, 5:00 am
You need a ip2country database

Steve136
Sep 7th 2008, 7:28 am
Thanks Jay6390, but i believe I am looking for what ammoun said. I need exact location based on the visitor's IP. Is this something that is quite complex or some readymade solutions are available?

Hi,

There is a PHP module that can be installed that'll do just that, it will tell you exactly what country an IP address is located in.

http://uk3.php.net/manual/en/ref.geoip.php

Regards,

Steve

hexadesigns
Sep 7th 2008, 8:46 am
Thanks Jay and Steve, I think I have got the solution. Enjoy some green. Both of you :D