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

Solution Steps

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;
}

Modify it to 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).