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?
 

Chris D

XenForo developer
Staff member
You're using:
Code:
$_SERVER['HTTP_X_FORWARDED_FOR'];
rather than:
Code:
$_SERVER['X_FORWARDED_FOR'];
 

trman

Active member
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'];
 

trman

Active member
You're using:
Code:
$_SERVER['HTTP_X_FORWARDED_FOR'];
rather than:
Code:
$_SERVER['X_FORWARDED_FOR'];

Clarification:

Code:
$_SERVER['HTTP_X_FORWARDED_FOR'];
shows visitor ip address as 127.0.0.1

Code:
$_SERVER['X_FORWARDED_FOR'];
shows no visitor ip address
 

Chris D

XenForo developer
Staff member
If the advice that Ezoic has given you doesn't appear to be correct, then you may have to clarify the issue with them directly.
 

trman

Active member
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.
 

Chris D

XenForo developer
Staff member
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.
 

Sal Collaziano

Active member
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?
 

trman

Active member
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']; }
 
Top