1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

IP record - Recording firewall IP instead of user

Discussion in 'XenForo Questions and Support' started by jackbrennan, May 5, 2013.

  1. jackbrennan

    jackbrennan Member

    Hi Community,

    I'm currently setting up my forum which is behind a UTM firewall. It seems the code used to record a users IP in Xenforo is using something similar to the following:

    $ip = $_SERVER['REMOTE_ADDR']

    However, that will return the Firewall IP address and not the user.

    I've got some code which will return the correct IP address of the visiting user, but I’m unsure where the actual IP function in Xenforo is to update it?

    There are just so many .php files o_O

    Any help would be greatly appreciated.

    Jack.
     
  2. tyteen4a03

    tyteen4a03 Well-Known Member

    If you aren't looking to write your own addon to do this, putting your IP translation logic in config.php is fine (however hacky it is)
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    There isn't a central function in XenForo for the client IP.

    Visit admin.php?tools/phpinfo and make sure REMOTE_ADDR shows your correct IP. If it's not correct then you can contact your host or server person to fix this. Or look for a server variable that contains the correct IP and then add this code to your library/config.php file:

    Code:
    // FIX IP ADDRESS FOR PROXY
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
    
    Replace the red part with the name of the server variable that contains the correct IP (from your phpinfo).
     
    Walter and jackbrennan like this.
  4. jackbrennan

    jackbrennan Member

    Thanks very much that gives me something to work with. REMOTE_ADDR in PHPinfo is just returning the firewall IP, so i'll have a play. I should be able to get it work by editing the config.php file.

    Thanks again.
    Jack.
     
  5. jackbrennan

    jackbrennan Member

    Hi,

    Just a quick update. This variable fixes the problem seeing as the firewall is acting as a proxy server for requests both leaving and coming to the webserver.

    HTTP_X_FORWARDED_FOR

    Thank you.
     

Share This Page