WordPress seems to use REMOTE_ADDR when storing IP addresses in the database, so all the comments in the database are IP addresses from various CDN servers. The article originates from a two-day blog- https://2days.org/85180.html
stay wp-config.ph
The following code can be added to the p file to obtain CDN
The real IP address of the back visitor. The core of this function is to use the parsed HTTP_X_FORWARDED_FOR
replace REMOTE_ADDR
。 The article originates from a two-day blog- https://2days.org/85180.html
//WordPress obtains the real IP address of visitors after using CDN if( ! empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { $get_HTTP_X_FORWARDED_FOR = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = trim($get_HTTP_X_FORWARDED_FOR[0]); }
The article originates from a two-day blog- https://2days.org/85180.html
This code can be used in PHP to obtain the customer's real IP address, even when using CDN. It checks HTTP_X_FORWARDED_FOR
Header. If it exists, its value will be decomposed into a comma separated list, and the first IP address will be taken as the real IP address of the client. Note that this method is not always accurate, because the client can forge this header, but it is usually reliable. The article originates from a two-day blog- https://2days.org/85180.html
Or you can use the following PHP code to obtain the real IP address of visitors in WordPress: The article originates from a two-day blog- https://2days.org/85180.html
function get_real_ip_address(){ if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; } return $_SERVER['REMOTE_ADDR']; }
Add this code to the functions.php
File, and then call the get_real_ip_address()
Function. The article originates from a two-day blog- https://2days.org/85180.html
The above are the methods I found on the Internet. I hope they are useful. The article originates from a two-day blog- https://2days.org/85180.html
The article originates from a two-day blog- https://2days.org/85180.html
Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!