Solving the Issue of Emlog Being Unable to Obtain the Real IP Address After Enabling a CDN
A few days ago, I wrote an article about “solving the issue of WordPress being unable to obtain the real IP address after enabling a CDN”. Today, I happened to see someone asking for help in a group. They were using Emlog and encountered the same situation (being unable to obtain the real IP address after enabling a CDN), so I thought I would try applying the WordPress solution to Emlog. It actually worked, so I’ll share the process below for everyone’s reference. Perhaps it can even solve the problem in other applications.

Solution
Open include/lib/function.base.php with an editor. Around line 60, you can find the following code:
function getIp() {
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
if (!ip2long($ip)) {
$ip = '';
}
return $ip;
}
Replace it with the following code:
function getIp() {
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = $list[0];
}
if (!ip2long($ip)) {
$ip = '';
}
return $ip;
}
Note
The above code has only been tested on Emlog version 5.3.1. Please test it yourself on other versions (it should theoretically work).
Comments
(0)No comments yet. Start the conversation.