/    Sign up×
Community /Pin to ProfileBookmark

Finding the browsers language problems

Hi,

I am currently obtaining the browsers language type using the following: –

[CODE]
// Get the users language
$users_lang = explode(“,”, getenv(“HTTP_ACCEPT_LANGUAGE”));
$users_lang = strtolower($users_lang[0]);

if(empty($users_lang)) {
$users_lang = “Unknown”;
}
[/CODE]

There is not a problem with the code perse, the problem i have is that it is coming up with 60% of them as unknown.

Is there a more efficient way to do it?

Thanks
k0r54

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bokehJan 23.2006 — Here's one way:[code=php]<?php
list($first_user_lang) = preg_split('/[,;]/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], 2);
echo $first_user_lang;
?>[/code]


On my website - English Spanish Translation - in my signature I do it differently. I run through $_SERVER['HTTP_ACCEPT_LANGUAGE'] and see which of the languages I provide comes earlier in the string. If not at all then I serve the default language (English). [URL=http://bokehman.com/calendar]On this page[/URL] I do the same with four languages.
Copy linkTweet thisAlerts:
@k0r54authorJan 24.2006 — Would that be more efficient than mine?

Why would yours pick up more than mine? (that not meant in any degrading way, i just want to know)

Thanks

k0r54
Copy linkTweet thisAlerts:
@bokehJan 24.2006 — Who knows? It's just that you said yours doesn't work 60% of the time. I can't replicate that error. The only time I can get it to output unknown is if I delete the browser languages.

What are you doing with that info? There might be a better way to do it.
Copy linkTweet thisAlerts:
@k0r54authorJan 24.2006 — ahhh ok lol,

It just for my clickcount

Thanks

k0r54
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...