在主题文件function.php下添加以下代码即可解决:6 ^ @( P7 T2 [; s3 f/ j
- /**
7 M1 s* v* s6 q, W - * 获取用户真实IP! O7 x7 L0 \; Z8 ?
- */
R5 b! T, Q8 D - function getIP()
9 U/ c7 f+ m+ u) z! z) s8 m' X - {2 c5 o( n6 E) Q3 j7 k
- static $realIP;
- [$ a0 Y4 o6 W7 C6 _9 e - if (isset($_SERVER)){* C1 O+ f) S9 I
- if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
/ S( W. c1 ]! B: R - $realIP = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);
3 v7 P" r! r/ b7 ? - $realIP = $realIP[0];
4 s5 \3 m- j; U: S) Q' e - } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$ m4 G. j7 f3 u; {. M - $realIP = $_SERVER["HTTP_CLIENT_IP"];3 e |2 c; f. ~/ M
- } else {
2 }+ b/ ~9 t' p - $realIP = $_SERVER["REMOTE_ADDR"];$ P2 x/ a7 z) ]: n, T$ ?& O* j" o
- }% I& `& v5 u* H
- } else {
# \9 s/ @" s- u0 s8 T5 j - if (getenv("HTTP_X_FORWARDED_FOR")){& \" I4 F" m3 Z. c* W4 {' ]. F$ \
- $realIP = getenv("HTTP_X_FORWARDED_FOR");
" }. T2 d* G9 o - } else if (getenv("HTTP_CLIENT_IP")) {% ~5 x( g: |& T; g
- $realIP = getenv("HTTP_CLIENT_IP");
2 y4 X2 c/ x# Q/ g4 G - } else {
$ |9 H1 F' k2 u$ K0 Z. P* u - $realIP = getenv("REMOTE_ADDR");' {7 _! }+ F$ D3 s+ c+ R
- }
2 x: U- i8 w" k6 x' m - }' g: U% ^* x( J$ L% l
- $_SERVER['REMOTE_ADDR'] = $realIP;5 a9 I4 S) f& [6 T
- //return $realIP;
0 T/ h( i: n* g1 U$ p8 ? - }
* d! a& ]; q' _. I( h - add_action( 'init', 'getIP' );
复制代码
4 g( |& t; S% ?6 K |