PDA

View Full Version : Greetings to the world... odd request




slipper
Jun 28, 2009, 05:13 PM
I have a site visited people throughout the world and i was curious is there is some sort of script or something (computer illiterate here) to display a welcome message depending on what country they are visiting from.



SrWebDeveloper
Jun 29, 2009, 12:03 PM
I'm sorry you are computer illiterate, you picked a topic which can be complex even for something as simple as this seems. Pass this onto your developer if this is beyond your skill level and experience. I offer 3 different solutions and explain it as simple as possible.

In a nutshell, you're referring to something called "geolocation", the act of retreiving the country of origin based on the IP address. The method of retreival is typically a database.

Warning: Some users lookup the browser's country code (not a database) which can be queried in most programming languages, but this data is extremely unreliable for many reasons and NOT suggested. I have other far better suggestions below...

PHP has a cool way of doing this, a simple command named "geop_country_name_by_name" (details here including example code (http://us3.php.net/manual/en/function.geoip-country-name-by-name.php)) where you can pass a hostname/IP and it returns the country. Problem, is PHP by default does not support the command. You'll need to extend PHP by adding in a PECL library named geoip version >= 0.2.0 which is compiled into PHP (guru level). This is something your webhost or system adminstrator would do, requiring knowledge of PECL/PEAR and PHP as documented here (http://www.php.net/manual/en/geoip.setup.php) for requirements/installation. You can download the library here (http://pecl.php.net/package/geoip). Once your admin installs it into PHP, the actual code is tiny to make it happen.

Beyond that, for standard PHP4/5 setups:

Here are 2 scripts I found that you can try, each written in PHP and both would need to be modified by someone who knows PHP/MySQL to do exactly what you want. But each has the two key components, how to identify the IP and how to query the country from the database based on that IP.

Geo-targeting - excellent, includes links on updating the database (http://www.analysespider.com/geo-targeting/geo-targeting.html)
Web Heavan Country Detector (http://www.web-heaven.com/)

Use the scripts as a starting point, ask your developer to modify it to not redirect (default behavior) but display the welcome after the query is made, simple as that.

Notes: IP's can be faked, the database must be updated occasionally - no method is perfect. Also, some scripts use GPS latitude/longitude instead of IP, but you still need a database lookup somehow, it's just more accurate.

-jim