PHP judgment browser, judgment language code sharing, php language _ PHP Tutorial

Source: Internet
Author: User
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 ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.