XF 1.5 X_FORWARDED_FOR

trman

Active member
I am using Ezoic, which puts my forum behind a proxy and my forum visitors original IP address does not show in my ACP, just the IP address of that Ezoic uses.

I think I need to use X_FORWARDED_FOR somewhere to get the real IP to show up. I have tried to put the following in config.php and it did not work:

Code:
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];

Ezoic is not much help, other than telling me I need to use X_FORWARDED_FOR.

Can anyone help?
 
Thanks Chris,

I changed it however now instead of showing the visitor ip as 127.0.0.1 it is blank in the AdminCp (under users awaiting approval).

I want to get the user's original IP address and use it in Xenforo for all the IP related functions, such as stop forum spam where the IP is checked, and so on.

Here is what I now have in my /library/config.php

Code:
$_SERVER['REMOTE_ADDR'] = $_SERVER['X_FORWARDED_FOR'];
 
Ezoic really did not give me any advice, other than to get the visitors original IP address I needed to implement X_Forwarded_FOR.

So I am just trying to figure out how to do that with Xenforo.
 
Sorry I wasn't clear: you are doing it correctly in XenForo, but it would appear as though the headers they recommended aren't returning the correct information.

So, this is absolutely correct:
Here is what I now have in my /library/config.php

Code:
$_SERVER['REMOTE_ADDR'] = $_SERVER['X'];
But you just need to clear up with them whatever the "X" is and question why it isn't returning the expected value. FWIW, I have since looked into various bits and "HTTP_X_FORWARDED_FOR" is indeed a valid header that some proxy providers set, which I believe is returning an empty string for you, so assuming now that is the correct header the question remains why is it blank, and that's something really only they can answer.
 
I'm using Ezoic as well - just started today - and I also added the line to config.php... I'm getting thousands of these errors in my log...

  • ErrorException: [E_NOTICE] Undefined index: HTTP_X_FORWARDED_FOR
  • src/config.php:19
  • Generated by: Unknown account
  • Jun 27, 2018 at 6:03 PM
Stack trace
#0 src/config.php(19): XF::handlePhpError(8, '[E_NOTICE] Unde...', '/home/site/...', 19, Array)
#1 src/XF/App.php(142): require('/home/site/...')
#2 src/XF/Container.php(28): XF\App->XF\{closure}(Object(XF\Container))
#3 src/XF/App.php(2758): XF\Container->offsetGet('config')
#4 src/XF/App.php(1511): XF\App->container('config')
#5 src/XF/Admin/App.php(40): XF\App->setup(Array)
#6 src/XF.php(312): XF\Admin\App->setup(Array)
#7 src/XF.php(324): XF::setupApp('XF\\Admin\\App')
#8 admin.php(13): XF::runApp('XF\\Admin\\App')
#9 {main}
Request state
array(4) {
["url"] => string(35) "/forum/admin.php?logs/server-error"
["referrer"] => string(69) "https://site.com/forum/admin.php?logs/server-error&page=519"
["_GET"] => array(1) {
["logs/server-error"] => string(0) ""
}
["_POST"] => array(0) {
}
}

Any advice?
 
I ended up using the Cloudflare App in Ezoic to connect to Ezoic via Cloudflare. And then, in order to make Cloudflare show the visitors original IP instead of Cloudflare's IP, I put this in my config.php

if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP']; }
 
This seems to be working for me

if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
 
Create a new php file (name it whatever you want, so long as its not an existing file) with the following content:

Code:
<?php 

echo '<pre>';
print_r($_SERVER);        
echo '</pre>';

Run this from your browser and it will list all the headers, so you can see which header, if any, your host's web server software is passing the correct IP address in.
 
This seems to be working for me

if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}

Hoping I can revive this old thread for a minute ... I'm trying to get Ezoic set up on XF 1.5.6 and wondering where this code above goes — in config.php?

If so, just add it at the bottom, or where does it need to go?

Advice is greatly appreciated, thank you.
 
Top Bottom