PDA

View Full Version : [PHP-ASP] Determinare in che lingua è il sistema operativo del client


GordonFreeman
25-07-2007, 17:35
I have to write a web page that determines the client OS language and then redirects the browser to the appropriate page (possibly in the same language).

Suppose the client browsers run on Windows NT/XP/2000/2003
Using client-side scripting, i can do it in this way:


<html>
<body>

<script language="vbscript">

For Each objOperatingSystem in GetObject( "winmgmts:").InstancesOf ("Win32_OperatingSystem")

' this cycle should be executed only once

if objOperatingSystem.OSLanguage = 9 then
'go to English page
location.href = "http://mypage.com/english.html"
elseif objOperatingSystem.OSLanguage = 1041 then
'go to Japanese page
location.href = "http://mypage.com/jap.html"
' etc...
end if

Next

</script>

</body>
</html>


The problem with the client-side approach is that IE will ask the user if he wants to execute the page or not, because it will detect active content within the script (the GetObject( ) call i guess).

I just want the page be opened without asking the user.

I think that retrieving client OS from server side will solve the problem, but is there a way to do it? using PHP, for example..

thanks in advance

anonimizzato
25-07-2007, 19:41
I don't know if you can do something like this.

I think that maybe is a good idea make a sniffer about the country's IP

Don't you think?

P.S.
Why did you write the title of the thread in italian and the body in english? :wtf:

Sorry for my english ;)

AngeL)
25-07-2007, 19:50
I don't know if you can do something like this.

I think that maybe is a good idea make a sniffer about the country's IP

Don't you think?

P.S.
Why did you write the title of the thread in italian and the body in english? :wtf:

Sorry for my english ;)

guarda che è italiano.. se leggi i suoi altri messaggi sono in italiano... :mbe:

cionci
25-07-2007, 22:22
Questa cosa è spesso risolvibile tramite server web...ad esempio Apache ha il modulo che redireziona il visitatore sulla pagine con la lingua giusta.
Ci sta che esista un isapi filter apposito anche per IIS.

GordonFreeman
26-07-2007, 10:31
certo che sono italiano :)
solo che quel post l'avevo prima messo su un altro forum in inglese e ho fatto copia e incolla, non avevo voglia di tradurre :D

comunque ho risolto, grazie..

per chi fosse interessato: per scoprire da lato server qual'è la lingua del client basta leggere l'header http ACCEPT-LANGUAGE che i browser mandano quando richiedono la pagina web


<?php
$acceptLang = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
/* fai il parsing della stringa ...
che è nel formato specificato nel
protocollo HTTP http://www.faqs.org/rfcs/rfc2616.html
*/
?>


ciao e grazie lo stesso