• Resolved ampli

    (@ampli)


    Incapsula CDN is similar to the cloudflare so to make it work with Incapsula I have added this code to the .htninja

    <?php
    /*
    +=====================================================================+
    | NinjaFirewall optional configuration file |
    | |
    | See: http://nintechnet.com/nfwp/1.1.3/ |
    | |
    +=====================================================================+
    */

    // Users of Cloudflare CDN:
    if (isset($_SERVER[‘HTTP_X_FORWARDED_FOR’]))
    {
    $_SERVER[‘REMOTE_ADDR’] = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
    }

    is this correct or I should change it to

    <?php
    /*
    +=====================================================================+
    | NinjaFirewall optional configuration file |
    | |
    | See: http://nintechnet.com/nfwp/1.1.3/ |
    | |
    +=====================================================================+
    */

    // Users of Cloudflare CDN:
    /**
    * This file should be included at the beginning of your PHP code
    *
    * It changes the value of $_SERVER[‘REMOTE_ADDR’], to the value provided in the Incap-Client-IP header.
    * If such a value is not provided, or is not valid – no change is made.
    */

    //name of HTTP header with the initial client IP address
    define(‘HEADER_NAME’,’HTTP_INCAP_CLIENT_IP’);

    try {

    //stop process if there is no header
    if (empty($_SERVER[HEADER_NAME])) throw new Exception(‘No header defined’, 1);

    //validate header value
    if (function_exists(‘filter_var’)) {
    $ip = filter_var($_SERVER[HEADER_NAME], FILTER_VALIDATE_IP);
    if (false === $ip) throw new Exception(‘The value is not a valid IP address’, 2);
    }
    else {
    $ip = trim($_SERVER[HEADER_NAME]);
    if (false === preg_match(‘/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/’, $ip)) throw new Exception(‘The value is not a valid IP address’, 2);
    }

    //At this point the initial IP value is exist and validated
    $_SERVER[‘REMOTE_ADDR’] = $ip;
    } catch (Exception $e) {}

    Code provided by incapsula to get correct ip
    http://support.incapsula.com/hc/en-us/articles/200628020-General-PHP-Applications
    https://github.com/wp-plugins/incapsula/blob/master/incapsula.php

    https://ww.wp.xz.cn/plugins/ninjafirewall/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nintechnet

    (@nintechnet)

    Try this code instead:

    <?php
    /*
    +=====================================================================+
    | NinjaFirewall optional configuration file |
    | |
    | See: http://nintechnet.com/nfwp/1.1.3/ |
    | |
    +=====================================================================+
    */
    
    // Users of Incapsula CDN:
    if (! empty($_SERVER["HTTP_INCAP_CLIENT_IP"]) &&
       filter_var($_SERVER["HTTP_INCAP_CLIENT_IP"], FILTER_VALIDATE_IP) ) {
    	$_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_INCAP_CLIENT_IP"];
    }
    Thread Starter ampli

    (@ampli)

    I have added the new code but is there any way I could check if it is working properly or not.

    To spread the word about Ninja I have written a post about it.

    Plugin Author nintechnet

    (@nintechnet)

    You can upload a simple PHP script like this one into your WP directory:

    <?php
    echo 'Your IP (REMOTE_ADDR) is : ' . $_SERVER["REMOTE_ADDR"];
    ?>
    Thread Starter ampli

    (@ampli)

    thanks for your help, it is detecting correct ip

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘For Incapsula CDN user’ is closed to new replies.