This article mainly to share the PHP to judge the browser, judge the language of the code, very simple, mainly on the server predefined variable $_server access analysis, here recommended to everyone.
-->
PHP programming often need to use some of the server data, special $_server detailed parameters, easy to use later.
Determine browser type
The code is as follows:
Type of judgment
<?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
The code is as follows:
<?php
$lang = substr ($_server[' http_accept_language '), 0, 4); Take only the first 4 digits, so you only judge the most preferred language. If take the first 5 digits, may appear the en,zh situation, affects 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 "中文版";
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 of information on the $_server access to the information of the server, I hope you can enjoy.