PHP judgment Browser, language code sharing, PHP language _php tutorial

Source: Internet
Author: User

PHP judgment Browser, language code sharing, PHP language


PHP programming often need to use some of the server's information, special $_server detailed parameters to organize, convenient for later use.

Determine browser type

Copy the Code code as follows:
Judging type
<?php
if (Strpos ($_server["Http_user_agent"], "MSIE 8.0"))
echo "Internet Explorer 8.0";
else if (Strpos ($_server["Http_user_agent"], "MSIE 7.0"))
echo "Internet Explorer 7.0";
else if (Strpos ($_server["Http_user_agent"], "MSIE 6.0"))
echo "Internet Explorer 6.0";
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

Copy the Code code as follows:
<?php
$lang = substr ($_server[' http_accept_language '), 0, 4); Take only the first 4 digits, so that only the most preferred language is judged. If take the first 5 bits, may appear en,zh situation, influence 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 "中文版";
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 "Japanese";
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 is a personal collation about $_server get server information commonly used information, I hope you can like.

http://www.bkjia.com/PHPjc/963841.html www.bkjia.com true http://www.bkjia.com/PHPjc/963841.html techarticle PHP Judge Browser, Judge language code sharing, PHP language PHP programming often need to use some of the server's information, special $_server detailed parameters to organize, convenient for later 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.