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

Create a template conditional based off Cloudflare GeoIP Header?

Discussion in 'XenForo Development Discussions' started by BamaStangGuy, Sep 28, 2016.

  1. BamaStangGuy

    BamaStangGuy Well-Known Member

    Cloudflare seems to include a header with every request that holds the visitors location. Would it be possible to create a template conditional based off this header?

    What is IP Geolocation?
    CloudFlare can geolocate visitors to your website and pass the country code on to you. Once enabled, we will then add an HTTP header named "CF-IPCountry" to all requests we make to your website.

    Note: CloudFlare includes this information for both IPv4 and IPv6 addresses.

    Would make it easy to target advertisements to specific countries without the use of robust ad server programs or additional queries to 3rd party services.

    Here is the code example. Looks pretty straight forward.

    PHP:
    $country_code $_SERVER["HTTP_CF_IPCOUNTRY"];
     
    Last edited: Sep 28, 2016
  2. Chris D

    Chris D XenForo Developer Staff Member

    There's a visitor_setup code event. If you utilise this, the variable will be part of the visitor object.

    It's not saved anywhere, it just makes the variable available in code and templates using the current $visitor / XenForo_Visitor object.
     
    BamaStangGuy likes this.

Share This Page