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

REMOTE_ADDR

Discussion in 'XenForo Development Discussions' started by dvsDave, Mar 6, 2011.

  1. dvsDave

    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?
     
  2. Kier

    Kier XenForo Developer Staff Member

    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;
        }
     
  3. a legacy reborn

    a legacy reborn Well-Known Member

    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...
     
  4. dvsDave

    dvsDave Well-Known Member


    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.
     
  5. Mike

    Mike XenForo Developer Staff Member

    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'];
    }
     
    Mr. Goodie2Shoes, Elly, Mouth and 5 others like this.
  6. George

    George Active Member

    Can you just add that to the core code so it supports Cloudflare by default????
     
  7. James

    James Well-Known Member

    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
     
  8. Mike

    Mike XenForo Developer Staff Member

    If you're not behind CF, then that makes the IPs more spoofable.
     
  9. George

    George Active Member

    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;
        } 
     
  10. George

    George Active Member

    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.
     
  11. dvsDave

    dvsDave Well-Known Member

  12. a legacy reborn

    a legacy reborn Well-Known Member

    I say put it in comments...those who need it uncomment it others can leave or remove it.
     
  13. lauren

    lauren Member

    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.png
     
  14. SkyeLogic

    SkyeLogic Member

    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.
     
  15. giorgino

    giorgino Well-Known Member

    Same with Mike's suggestion... Any news?
     
    lalalatrululu likes this.
  16. lalalatrululu

    lalalatrululu Member

    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
     
  17. Spenser

    Spenser Active Member

    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.
     
    Mouth and Jake Bunce like this.
  18. SneakyDave

    SneakyDave Well-Known Member

    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.
     
  19. Cujo

    Cujo Member

    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.
     

Share This Page