FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » recognize country
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: recognize country [message #184209 is a reply to message #184200] Sun, 15 December 2013 14:22 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
Senior Member
nawfer, 2013-12-15 11:34:

>>> GeoIP.
>>
>> Which is just as accurate as any other IP-based location service. IOW,
>> not very.
>
> but is a online service or one php array or both
> ?
>
>
> but isn't stable the ip of the nations?
> example
> 50.xxx.xxx.xxx to 100.xxx.xxx.xxx all ip nation A
> 101.xxx.xxx.xxx to 150.xxx.xxx.xxx all ip nation B
> 151.xxx.xxx.xxx to 200.xxx.xxx.xxx all ip nation C

No - it does not work that way.

> ok the ip inner nations ip can't be accurate and can to change, but between
> nation is table (every range is assigned at only one nation)?

No.

IP ranges are assigned to providers - and providers can operate in
multiple countries. And by the way - there is also IPv6.

But you still did not answer what you want to achieve.

If you want to handle different languages, you should better use the
Accept-Language header oft the browser - and even then the visitor
should be able to manually select the language, just in case the browser
does not send an Accept-Language header at all or there is no "known"
language in the list of accepted languages.

Also see: <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>

And for example - if you have content in English, French in Italian and
you want to deliver it depending on the users browser settings (yes, the
quality value of each language is ignored, since literally all browsers
send the preferred languages in the order of preference):

<?php
// This is the list of languages we support

$knownlanguages = { 'en', 'fr', 'it' };

// This is the active language in which the content
// is being served - 'en' by default

$activelanguage = 'en';

// Build an array of languages based on the Accept-Language
// header the browser sends

$languages = explode(',', preg_replace('/(;q=\d+.\d+)/i',
'', getenv('HTTP_ACCEPT_LANGUAGE')));

// Now go through the list and check if the browser
// supports any of "our" languages

foreach ($languages as $language) {
if (in_array($language, $knownlanguages)) {
// Language is known, then use this and stop
// checking the remaining entries
$activelanguage = $language;
break;
}
}

// Now $activelanguage contains one of our supported
// languages which is also accepted by the browser
?>

BTW: You can see this in action on my private site
<http://arnowelzel.de>. The code is not identical, but very similar. The
site will redirect to the English or German version depending on what
language the browsers prefers or defaults to German if no "known"
language was given. However it is always possible to change the language
using the "language" links in the header.



--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Apache HTTP Server
Next Topic: activating a JS script from PHP redirect
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Jul 01 23:46:23 GMT 2024

Total time taken to generate the page: 0.04824 seconds