MCPcopy Create free account
hub / github.com/CoderOpen/waimai / getLanguage

Function getLanguage

bootstrap/function.php:36–55  ·  view source on GitHub ↗

* 根据ip获取客户端语言 * @return string */

()

Source from the content-addressed store, hash-verified

34 * @return string
35 */
36function 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

Callers

nothing calls this directly

Calls 1

getClientIpFunction · 0.85

Tested by

no test coverage detected