WP WHMCS Integration Improvement

I'd like to request the improvement of the way that WP WHMCS Integration operates with IPv6 and Nginx. When operating within a nginx/apache install, you come across a problem where the REMOTE_ADDR shows as the IPv6 address of the server, not of the user. In a case like this, at least with the way Plesk handles the install, the $_SERVER variable HTTP_X_FORWARDED_FOR is automatically applied to allow the passing of the correct IP to the system. WHMCS accepts and operates this without any problems if you access directly; however, WHMCS WP Integration does not pass this variable on. Instead, per line 611 of whmcs-integration.php, the system passes the ['REMOTE_ADDR']. In a standard IPv4 connection, that doesn't pose a problem. However, with IPv6, it doesn't seem to pass correctly.

I've modified the source to match the following, which I believe will get the issue resolved. I'm working on testing it right now from an external source, after which I'll say this did the job. If it doesn't, I'll post a follow up saying that there is still an issue somewhere, but I'll continue to work on it.

Remove / Comment line 611 ($forward =...) and insert the following lines below it.
if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
$forward = $_SERVER['HTTP_X_REAL_IP'];
} else {
$forward = $_SERVER['REMOTE_ADDR'];

  • Vhc-John


    Please flag the updated code below for the primary coder. I've tested this, modified version, and it appears to be working properly for my install. My setup is as follows:

    Plesk 12.0.18 (latest build), running Apache and nginx. I've modified the whmcs-integration.php file (from version 1.3) at line 611 to remove the previous $forward =.. line, replacing it with this:

    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                            $theIp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
                            $forward .= $theIp[0];
                    } else {
                            $forward = $_SERVER['REMOTE_ADDR'];

    For me, results are now showing the correct IP Address. I did have to add the IPv6 address (which was already added) in the Setup -> General -> Security -> Trusted Proxies list.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.