Support » Plugin: Restricted Site Access » Great Plugin – minor bug with using when behind a load balancer

  • Great Plugin though there was a minor bug when using behind a load balancer. The IP address would always be of the load balancer. To fix edit the restricted-site-access/restricted_site_access.php file and add this function

    public static function get_ip() {

    //Just get the headers if we can or else use the SERVER global
    if ( function_exists( ‘apache_request_headers’ ) ) {
    $headers = apache_request_headers();
    } else {
    $headers = $_SERVER;
    }
    //Get the forwarded IP if it exists
    if ( array_key_exists( ‘X-Forwarded-For’, $headers ) ) {
    $the_ip = $headers[‘X-Forwarded-For’];
    } elseif ( array_key_exists( ‘HTTP_X_FORWARDED_FOR’, $headers )) {
    $the_ip = $headers[‘HTTP_X_FORWARDED_FOR’];
    } else {

    $the_ip = $_SERVER[‘REMOTE_ADDR’];
    }
    return $the_ip;
    }

    Then replace all occurrences of: $_SERVER[‘REMOTE_ADDR’] with self::get_ip()

    • This topic was modified 1 year, 11 months ago by  ifdb314.
  • The topic ‘Great Plugin – minor bug with using when behind a load balancer’ is closed to new replies.