* 根据ip获取客户端语言 * @return string */
()
| 34 | * @return string |
| 35 | */ |
| 36 | function getLanguage() |
| 37 | { |
| 38 | if (empty($_COOKIE['lang'])) { |
| 39 | $ip = getClientIp(); |
| 40 | $url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip; |
| 41 | try { |
| 42 | $res = file_get_contents($url); |
| 43 | } catch (Exception $e) { |
| 44 | |
| 45 | } |
| 46 | if (!empty($res)) { |
| 47 | $ipData = json_decode($res, true); |
| 48 | if ($ipData['code'] == 0 && in_array($ipData['data']['country_id'], ['CN', 'HK', 'TW'])) { |
| 49 | $_COOKIE['lang'] = 'zh'; |
| 50 | } |
| 51 | } |
| 52 | $_COOKIE['lang'] = 'en'; |
| 53 | } |
| 54 | return $_COOKIE['lang']; |
| 55 | } |
| 56 | |
| 57 | |
| 58 |
nothing calls this directly
no test coverage detected