SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting visitor's country

    I have this kind of problem: how to redirect visitor to appropriate language site.
    For example, I'm from estonia and if I visit my site, i'd like to be redirected estonian page. But if you are from russia, then to russian page, others to english page...

    I know it is possible, cause i have seen those pages.

    All advice is wellcome.

    Sannu

  2. #2
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see in Sourceforge.net

    I think maybe check ip, becuase some ip range certain from some country.
    I live in Thailand. My English grammar not well.

  3. #3
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Php variable:
    $HTTP_ACCEPT_LANGUAGE
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, $HTTP_ACCEPT_LANGUAGE gives a list of all languages accepted by the browser

    You need to use gethostbyaddr on the user's IP and then match that against a country list

    http://www.php.net/manual/en/function.gethostbyaddr.php

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    No, $HTTP_ACCEPT_LANGUAGE gives a list of all languages accepted by the browser

    You need to use gethostbyaddr on the user's IP and then match that against a country list

    http://www.php.net/manual/en/function.gethostbyaddr.php

    Sean
    Try to go to a page with phpinfo(), and you will see that HTTP_ACCEPT_LANGUAGE indeed displays your language of choice. I have an english XP system, but my national settings are set to swedish, and lo and behold - $HTTP_ACCEPT_LANGUAGE == "sv"
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  6. #6
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked already, I use Thai Windows and $HTTP_ACCEPT_LANGUAGE == "th"

    and gethostbyaddr is possible one but if host is .com, It don't know what language to display.
    I live in Thailand. My English grammar not well.

  7. #7
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't know if you're talking about dynamic pages in PHP or static ones. if it's something done dynamically in PHP, then you'll have to use HTTP_ACCEPT_LANGUAGE and your own logic.

    however, if it's for static files, and you want to have a seperate copy of the file for each language, Apache can handle it itself with the Options MultiViews directive. simply name your files file.html.xx where xx is the language code (e.g. file.html.en) and when file.html is requested, Apache will give the correct "version" of file.html depending on the client's HTTP_ACCEPT_LANGUAGE. i've never used it, but i think that's how it works.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a place where I can get list of $HTTP_ACCEPT_LANGUAGE string values?

  9. #9
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whilst automatic redirection is all well and good, I would be tempted to simply give them a splash page and let them choose where to go, then just set a cookie so it remembers which page they want next time. Otherwise you could be sending people all over the place to places they don't want to go to!
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  10. #10
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by truelight
    Try to go to a page with phpinfo(), and you will see that HTTP_ACCEPT_LANGUAGE indeed displays your language of choice.
    Sorry Mattias, I was doing it by Country

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  11. #11
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    heh

    Autodetecting by country is virtually impossible - too many .com domains. If you specifically need country, a splash screen is needed. However, in 99% of the cases, I think just detecting language is adequate.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  12. #12
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found a site that promised just that... something like 95% of the ip-adress mapped I can't find it anymore doug... maybe this helps

    http://www.cybergeography.org/geogra...yberspace.html

    greets

    peanuts
    the neigbours (free) WIFI makes it just a little more fun


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •