PHP judges browsers, judges language code sharing, and php languages. PHP judges the browser and judges the language code for sharing. some SERVER information is often used in php programming. the detailed parameters of $ _ SERVER are sorted out for future use. PHP judgment browser, judgment language code sharing, php language
Some SERVER information is often used in PHP programming. the detailed parameters of $ _ SERVER are sorted out for future use.
Determine the browser type
The code is as follows:
// Determine the type
<? Php
If (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "MSIE 8.0 "))
Echo & quot; Internet Explorer 8.0 & quot ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "MSIE 7.0 "))
Echo & quot; Internet Explorer 7.0 & quot ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "MSIE 6.0 "))
Echo & quot; Internet Explorer 6.0 & quot ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "Firefox/3 "))
Echo "Firefox 3 ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "Firefox/2 "))
Echo "Firefox 2 ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "Chrome "))
Echo "Google Chrome ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "Safari "))
Echo "Safari ";
Else if (strpos ($ _ SERVER ["HTTP_USER_AGENT"], "Opera "))
Echo "Opera ";
Else echo $ _ SERVER ["HTTP_USER_AGENT"];
?>
Judgment language
The code is as follows:
<? Php
$ Lang = substr ($ _ SERVER ['http _ ACCEPT_LANGUAGE '], 0, 4); // only the first four digits are used to determine the preferred language. If the first five digits are obtained, en and zh may occur, affecting the judgment.
If (preg_match ("/zh-c/I", $ lang ))
Echo "simplified Chinese ";
Else if (preg_match ("/zh/I", $ lang ))
Echo "traditional Chinese ";
Else if (preg_match ("/en/I", $ lang ))
Echo "English ";
Else if (preg_match ("/fr/I", $ lang ))
Echo "French ";
Else if (preg_match ("/de/I", $ lang ))
Echo "German ";
Else if (preg_match ("/jp/I", $ lang ))
Echo "Japan ";
Else if (preg_match ("/ko/I", $ lang ))
Echo "Korean ";
Else if (preg_match ("/es/I", $ lang ))
Echo "Spanish ";
Else if (preg_match ("/sv/I", $ lang ))
Echo "Swedish ";
Else echo $ _ SERVER ["HTTP_ACCEPT_LANGUAGE"];
?>
The above are some common information about getting SERVER information from $ _ SERVER. I hope you will like it.
Some SERVER information is often used in PHP programming. the detailed parameters of $ _ SERVER are sorted out to facilitate future use ....