{"id":759,"date":"2026-06-01T11:16:43","date_gmt":"2026-06-01T03:16:43","guid":{"rendered":"https:\/\/hhh3m.top\/?p=759"},"modified":"2026-06-01T11:16:47","modified_gmt":"2026-06-01T03:16:47","slug":"%e8%ae%bf%e5%ae%a2-ip-%e5%bd%92%e5%b1%9e%e5%9c%b0%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/hhh3m.top\/index.php\/2026\/06\/01\/%e8%ae%bf%e5%ae%a2-ip-%e5%bd%92%e5%b1%9e%e5%9c%b0%e6%9f%a5%e8%af%a2\/","title":{"rendered":"\u8bbf\u5ba2 IP \u5f52\u5c5e\u5730\u67e5\u8be2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\u6e90\u4ee3\u7801\uff0c\u653e\u5728sidebar.php\u8fb9\u680f\u5408\u9002\u7684\u4f4d\u7f6e\u91cc<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e09\u65b9 API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982ip-api.com<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nif (!empty($_SERVER&#91;'HTTP_CLIENT_IP'])) {\n    $ip = $_SERVER&#91;'HTTP_CLIENT_IP'];\n} elseif (!empty($_SERVER&#91;'HTTP_X_FORWARDED_FOR'])) {\n    $ip = $_SERVER&#91;'HTTP_X_FORWARDED_FOR'];\n} else {\n    $ip = $_SERVER&#91;'REMOTE_ADDR'];\n}\n\n$api = \"http:\/\/ip-api.com\/json\/{$ip}?lang=zh-CN\";\n$response = wp_remote_get($api);\n$data = json_decode(wp_remote_retrieve_body($response), true);\n$area = $data&#91;'regionName'] . ' ' . $data&#91;'city'];\n?>\n\n&lt;div class=\"card-body text-center leftbar-search-button\">\n    &lt;div>\n        \u6b22\u8fce\u6765\u81ea &lt;?php echo $area; ?> \u7684\u670b\u53cb&lt;br>\n        \u5f53\u524d IP\uff1a&lt;?php echo $ip; ?>\n    &lt;\/div>\n&lt;\/div><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u672c\u5730\u6570\u636e\u5e93<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0b\u8f7d\u5b98\u65b9 PHP \u5e93<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbf\u95ee\u00a0<a href=\"https:\/\/github.com\/ip2location\/ip2location-php-module\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/ip2location\/ip2location-php-module<\/a>\u00a0\uff0c\u627e\u5230\u00a0<code>src<\/code>\u00a0\u6587\u4ef6\u5939\uff0c\u4e0b\u8f7d\u91cc\u9762\u7684\u00a0<code>Database.php<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0b\u8f7d\u6570\u636e\u5e93\u6587\u4ef6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbf\u95ee\u00a0<a href=\"https:\/\/lite.ip2location.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/lite.ip2location.com<\/a>\u00a0\u6ce8\u518c\u514d\u8d39\u8d26\u53f7\uff0c\u4e0b\u8f7d\u00a0<strong>DB3.LITE<\/strong>\u00a0\u7248\u672c\u7684 BIN \u6587\u4ef6\u3002DB3 \u5305\u542b\u56fd\u5bb6\u3001\u7701\u4efd\u3001\u57ce\u5e02\u4e09\u4e2a\u5b57\u6bb5\uff0c\u514d\u8d39\u7248\u6bcf\u6708\u66f4\u65b0\u4e00\u6b21<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u653e\u7f6e\u6587\u4ef6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 WordPress \u7684\u4e3b\u9898\u76ee\u5f55\u4e0b\u65b0\u5efa\u00a0<code>location<\/code>\u00a0\u6587\u4ef6\u5939\uff0c\u4f8b\u5982\u6211\u7684argon\u4e3b\u9898\u8def\u5f84\u4e3a\u00a0<code>\/wp-content\/themes\/argon\/location\/<\/code>\uff0c\u5c06\u4e0b\u8f7d\u7684\u00a0<code>Database.php<\/code>\u00a0\u548c\u00a0<code>IP2LOCATION-LITE-DB3.BIN<\/code>\u00a0\u653e\u5165<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7f16\u5199\u4ee3\u7801<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">php\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u3002\u9ed8\u8ba4\u5730\u5740\u90fd\u662f\u82f1\u6587\uff0c\u6211\u53ea\u60f3\u5b9e\u73b0\u5230\u7701\u7ea7\u7684\u5b9a\u4f4d\uff0c\u6240\u4ee5\u628a\u6240\u6709\u7701\u4efd\u5199\u8fdb\u6620\u5c04\u8868\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;div class=\"card-body text-center leftbar-search-button\" style=\"padding: 12px; font-size: 14px; line-height: 1.6;\"><br>    &lt;?php<br>    require_once( dirname(__FILE__) . '\/location\/Database.php' );<br><br>    $region_map = [<br>    'Beijing' => '\u5317\u4eac', 'Shanghai' => '\u4e0a\u6d77', 'Tianjin' => '\u5929\u6d25', 'Chongqing' => '\u91cd\u5e86',<br>    'Guangdong' => '\u5e7f\u4e1c', 'Guangxi' => '\u5e7f\u897f', 'Hainan' => '\u6d77\u5357', 'Fujian' => '\u798f\u5efa',<br>    'Zhejiang' => '\u6d59\u6c5f', 'Jiangsu' => '\u6c5f\u82cf', 'Shandong' => '\u5c71\u4e1c', 'Liaoning' => '\u8fbd\u5b81',<br>    'Hebei' => '\u6cb3\u5317', 'Henan' => '\u6cb3\u5357', 'Hubei' => '\u6e56\u5317', 'Hunan' => '\u6e56\u5357',<br>    'Jiangxi' => '\u6c5f\u897f', 'Shaanxi' => '\u9655\u897f', 'Shanxi' => '\u5c71\u897f', 'Sichuan' => '\u56db\u5ddd',<br>    'Yunnan' => '\u4e91\u5357', 'Guizhou' => '\u8d35\u5dde', 'Anhui' => '\u5b89\u5fbd', 'Gansu' => '\u7518\u8083',<br>    'Qinghai' => '\u9752\u6d77', 'Heilongjiang' => '\u9ed1\u9f99\u6c5f', 'Jilin' => '\u5409\u6797', 'Neimenggu' => '\u5185\u8499\u53e4',<br>    'Ningxia' => '\u5b81\u590f', 'Xinjiang' => '\u65b0\u7586', 'Xizang' => '\u897f\u85cf', 'Taiwan' => '\u53f0\u6e7e',<br>    'Hong Kong' => '\u9999\u6e2f', 'Macau' => '\u6fb3\u95e8'<br>    ];<br>    $bin_file = dirname(__FILE__) . '\/location\/IP2LOCATION-LITE-DB3.BIN';<br><br>    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {<br>        $ip = $_SERVER['HTTP_CLIENT_IP'];<br>    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {<br>        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];<br>    } else {<br>        $ip = $_SERVER['REMOTE_ADDR'];<br>    }<br><br>    if (empty($ip) || $ip == '127.0.0.1') {<br>        $area = '\u5730\u7403';<br>    } elseif (!file_exists($bin_file)) {<br>        $area = '\u6570\u636e\u5e93\u672a\u627e\u5230';<br>    } else {<br>        $ip2location = new \\IP2Location\\Database($bin_file, \\IP2Location\\Database::FILE_IO);<br>        $records = $ip2location->lookup($ip);<br>        $region_en = $records['regionName'] ?? '';<br>        $area = $region_map[$region_en] ?? ($records['countryName'] ?? '\u672a\u77e5\u5730\u533a');<br>    }<br>    ?><br><br>&lt;div class=\"card-body text-center leftbar-search-button\"><br>    &lt;div><br>        \u6b22\u8fce\u6765\u81ea &lt;?php echo $area; ?> \u7684\u670b\u53cb&lt;br><br>        \u5f53\u524d IP\uff1a&lt;?php echo $ip; ?><br>    &lt;\/div><br>&lt;\/div><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\u6e90\u4ee3\u7801\uff0c\u653e\u5728sidebar.php\u8fb9\u680f\u5408\u9002\u7684\u4f4d\u7f6e\u91cc \u7b2c\u4e09\u65b9 API \u4f8b\u5982ip-api.com \u672c\u5730 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-759","post","type-post","status-publish","format-standard","hentry","category-misc","tag-26"],"_links":{"self":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts\/759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/comments?post=759"}],"version-history":[{"count":1,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts\/759\/revisions\/760"}],"wp:attachment":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/media?parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/categories?post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/tags?post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}