Jump to content

visitor language and os check


jacko310592

Recommended Posts

hey guys,

i am currently trying to find a good way to get a visitors language and OS, at the moment i have...

 

language:

<?php
$languageList = array(

//other languages here
'en-gb' => 'English (United Kingdom)',
//other languages here

);

$userLanguage =  $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$userLanguage = explode(',', $userLanguage);
$CurrLanguage = strtolower($userLanguage[0]);
if ($languageList[$CurrLanguage] == ""){$CurrLanguage = 'Unknown Language';}
else {$CurrLanguage = $languageList[$CurrLanguage];}

?>

as you can see, all i have done was call HTTP_ACCEPT_LANGUAGE and split it at any ','

is this method full-proof though? or will there be a problem with some browsers?

 

 

OS:

<?php
$OSList = array
(

//other os's here
'Windows 7' => '(Windows NT 6.1)',
//other os's here

);

foreach($OSList as $CurrOS=>$Match)
{
        if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))
        {
                break;
        }
}
?>

as you can see, this uses the eregi function, which i dont want to use as soon it will be useless,  can anyone this of an alternative way of doing this?

 

 

thanks for reading

Link to comment
https://forums.phpfreaks.com/topic/193905-visitor-language-and-os-check/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.