在主题文件function.php下添加以下代码即可解决:( D. l2 u8 y b V2 S5 A
- /**6 j( ^2 w$ w7 ~
- * 获取用户真实IP3 m- @# I! B- Y5 W4 Y6 K; I
- */
* j- [' y+ t: T7 k - function getIP(), f7 j: }6 |6 i: L$ F
- {
, ^ N: f; u9 h' { - static $realIP;* O4 _: }) c' T- b6 G. E
- if (isset($_SERVER)){
0 J% e) i. J4 C# @! Z. k1 B& R - if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ r; l! P* b+ o2 Q! V% _: Y - $realIP = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);
8 U7 o* d: Z- T. K - $realIP = $realIP[0];
# m# g# l0 U3 O$ e/ `+ m - } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {! X6 O) S1 @0 G4 o4 p$ w' A
- $realIP = $_SERVER["HTTP_CLIENT_IP"];
/ A3 t( d, N5 i/ s2 s1 M/ l! z' F - } else {- Q8 B, X8 {, E6 I s7 Z, A
- $realIP = $_SERVER["REMOTE_ADDR"];
3 \4 \, B1 H% A9 z - }
) Q8 g3 `" Y8 _ - } else {
/ B# p) q, ~4 g, B" J1 u - if (getenv("HTTP_X_FORWARDED_FOR")){
/ w" W4 j7 O/ n7 e% v7 [ - $realIP = getenv("HTTP_X_FORWARDED_FOR");5 v2 C- J/ x5 X2 ]! D( J
- } else if (getenv("HTTP_CLIENT_IP")) {4 E/ u# s. J0 l
- $realIP = getenv("HTTP_CLIENT_IP");
" T* p2 J; h4 E0 ^ - } else {
; I E8 e% n! L8 z! ~- C. F' q - $realIP = getenv("REMOTE_ADDR");
/ |# f7 q# y( V/ d0 @- { - }
7 z; S: H. Z9 _( n+ q - }
3 W! @ o5 w% v1 c4 K, \ - $_SERVER['REMOTE_ADDR'] = $realIP;
" b5 p! c n3 y) j4 Y5 X- y, ] - //return $realIP;
5 f9 a/ h, ]# I$ k& n - }, I7 I. N# T- X& R+ l: w$ M, x
- add_action( 'init', 'getIP' );
复制代码 e$ P6 Q0 L/ x# ?& W) U) [
|