REMOTE_ADDR

dvsDave

Well-known member
Hey Guys,

I'm using CloudFlare's service and as a result, all of the traffic looks like it's coming from Cloudflare's servers.

They have a workaround where you replace the part of the forum code that grabs the visitors IP from the default "REMOTE_ADDR" to "HTTP_CF_CONNECTING_IP"

What php file grabs that IP address for visitors/users?
 
It's handed off to Zend_Controller_Request_Http::getClientIp().
PHP:
    /**
     * Get the client's IP addres
     *
     * @param  boolean $checkProxy
     * @return string
     */
    public function getClientIp($checkProxy = true)
    {
        if ($checkProxy && $this->getServer('HTTP_CLIENT_IP') != null) {
            $ip = $this->getServer('HTTP_CLIENT_IP');
        } else if ($checkProxy && $this->getServer('HTTP_X_FORWARDED_FOR') != null) {
            $ip = $this->getServer('HTTP_X_FORWARDED_FOR');
        } else {
            $ip = $this->getServer('REMOTE_ADDR');
        }

        return $ip;
    }
 
I want to say /library/XenForo/Session.php but it could be /library/XenForo/Visitor.php but I'd go with session because that was the one that first came to mind.


Edit: Darn u Kier! I was wrong anyways it appears...
 
It's handed off to Zend_Controller_Request_Http::getClientIp().


Hey Kier,

Thanks for the quick response! I changed the REMOTE_ADDR to HTTP_CF_CONNECTING_IP, but I'm not sure it worked. The rules about checking for proxy might be interfering.
 
Can you just add that to the core code so it supports Cloudflare by default????
Is Cloudflare a popular service? It seems like something like this is for the minority, so it probably didn't occur to the developers to do that.
However, as you can see, it's not that hard to do :D
 
If you do not use Cloudflare you should. It is one of the best services I have used for a DNS service. It blocks about 80% of my spam at the DNS level.

Plus what would it hurt every one else if it was there as it will not work unless you use Cloudflare.

PHP:
   /**
     * Get the client's IP addres
     *
     * @param  boolean $checkProxy
     * @return string
     */
    public function getClientIp($checkProxy = true)
    {
        if ($checkProxy && $this->getServer('HTTP_CLIENT_IP') != null) {
            $ip = $this->getServer('HTTP_CLIENT_IP');
        } else if ($checkProxy && $this->getServer('HTTP_X_FORWARDED_FOR') != null) {
            $ip = $this->getServer('HTTP_X_FORWARDED_FOR');
        } else if ($checkProxy && $this->getServer('HTTP_CF_CONNECTING_IP') != null) {
            $ip = $this->getServer('HTTP_CF_CONNECTING_IP');
         }else {
            $ip = $this->getServer('REMOTE_ADDR');
        }

        return $ip;
    }
 
If you're not behind CF, then that makes the IPs more spoofable.
AHHH Maybe have a check box in the AdminCP. Or you could just put a hook there and I can make a addon to support Cloudflare. With a on and off Checkbox and I am sure Xenforo and Cloudflare will both benefit.
 
It's easier to just put this in config.php:

PHP:
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

i added this to my config and it is still showing the cloudflare ips for all my members.
is there more to it than this?

0062.webp
 
Same, I used Mike's suggestion and the cloudflare IPs are still coming up.

Not entirely sure what the problem is yet... Will keep checking.
 
any news?
after changing to cloudflare people at forum lost authorization,'cos index page is cached
how can i fix that?

also, users can't login from index page
 
I use cloudflare both with lighttpd and nginx.

Here are the necessary steps for nginx: http://support.cloudflare.com/kb/troubleshooting/does-cloudflare-have-an-ip-module-for-nginx

And for lighttd you only have to add this to your config:
Code:
#Cloudflare
$HTTP["remoteip"] == "204.93.240.0/24" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
$HTTP["remoteip"] == "204.93.177.0/24" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
$HTTP["remoteip"] == "199.27.128.0/21" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
$HTTP["remoteip"] == "173.245.48.0/20" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
$HTTP["remoteip"] == "103.22.200.0/22" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
$HTTP["remoteip"] == "141.101.64.0/18" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
$HTTP["remoteip"] == "108.162.192.0/18" {
extforward.forwarder = ( "all" => "trust" )
extforward.headers = ("CF-Connecting-IP")
}
Works like a charm.
 
Regarding Mike's and Kier's suggestion to add the code to config.php to assign HTTP_CF_CONNECTING_IP to REMOTE_ADDR if it exists. It works for me, but of course, it will only take affect on new visits/posts. Any IP's recorded to the database prior to the change will still reference CloudFlare IP's. Don't know if that's what anybody's issue is, but took me a second to realize that.
 
It's easier to just put this in config.php:

PHP:
if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
This code is not working for me. I think it used to (I took a break from Cloudflare but now I use it again), but now all that is registered is a Cloudflare IP.
 
Top Bottom