Greetings to the world... odd request

Discussion in 'Web Design and Development' started by slipper, Jun 28, 2009.

  1. slipper macrumors 68000

    slipper

    Joined:
    Nov 19, 2003
    #1
    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.
     
  2. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #2
    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) 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 for requirements/installation. You can download the library here. 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
    Web Heavan Country Detector

    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
     

Share This Page