X_forwarded_for

Discussion in 'Troubleshooting' started by flfootytv, Apr 18, 2010.

  1. flfootytv

    flfootytv New Member

    Joined:
    Nov 10, 2007
    Messages:
    15
    Hi there,

    We currently are running our site through 2 loadbalancing squid proxies. This is resulting in amember seeing everyones IP as the proxy IPs. This is causing problems like such:

    Code:
    MYSQL ERROR:
    Duplicate entry '::ffff:xxx.xxx.xxx-2' for key 2
    in query:
    INSERT INTO amember_failed_login (ip, login_type, failed_logins, last_failed) VALUES ('::ffff:xx.xxx.xxx.xxx', '2', 1, 1271645241)
    
    Now, we have turned on Forwarded-For in the squid config file, and we have enabled it in the lighttpd config also. All we require now is for aMember to read the X_FORWARDED_FOR instead of the REMOTE_ADDR header.

    How would we go about doing this?

    Any help is very much appreciated
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    If requests are coming ONLY via proxy, edit file amember/config.inc.php
    add line right after opening <?php

    $_SERVER['REMOTE_ADDR'] = @$_SERVER['X_FORWARDED_FOR'];
  3. flfootytv

    flfootytv New Member

    Joined:
    Nov 10, 2007
    Messages:
    15
    Which in turn now produces these errors and logs no IP address:

    Code:
    WARNING: gethostbyaddr() [function.gethostbyaddr]: Address is not a valid IPv4 or IPv6 address in line 1605 of file mysql.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /var/www/amember/rconfig.inc.php:401) in line 371 of file check.inc.php
    WARNING: Cannot modify header information - headers already sent by (output started at /var/www/amember/rconfig.inc.php:401) in line 372 of file check.inc.php
    
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Remove this from mysql.inc.php:
    Code:
            if (preg_match('/proxy\.aol\.com$/', gethostbyaddr($REMOTE_ADDR)))
                return;
    
    should help.
  5. flfootytv

    flfootytv New Member

    Joined:
    Nov 10, 2007
    Messages:
    15
    Yeah that helps, but in the aMember CP it is not logging any IP address with that code at the top of config.inc.php.

    We're getting there :cool:
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Try to print_r($_SERVER) and check for X_FORWARDED_FOR may be it's empty?
  7. flfootytv

    flfootytv New Member

    Joined:
    Nov 10, 2007
    Messages:
    15
    fixed.

    Right to let everyone else know the header coming from squid proxy is not 'X_FORWARDED_FOR'

    but it is

    'HTTP_X_FORWARDED_FOR'

    which the above post helped me to find out so thank you.

    I hope this can help others with the same issues as me :)

    Thanks again

Share This Page