getgrav / grav-premium-issues

Official Grav Premium Issues repository to report problems or ask questions regarding the Premium products offered.
https://getgrav.org/premium
7 stars 2 forks source link

How can I retreive the IP Geolocation data via Cloudflare manager? #304

Closed danjames68 closed 2 years ago

danjames68 commented 2 years ago

I need to use the Geolocation data, Cloudflare says it needs pulling from CF-IPCountry HTTP Header - I had hoped to find some notes in the Cloudflare plugin to shortcut this process.

w00fz commented 2 years ago

Hey @danjames68 , the way Cloudflare work is they inject those headers in the response. You can easily retrieve these via Grav already, through they URI::getAllHeaders method. For example in any of your twig files you can do:

Country: {{ grav.uri.getAllHeaders['Cf-Ipcountry'] }}
IP: {{ grav.uri.getAllHeaders['Cf-Connecting-Ip']) }}

Hope this helps!

danjames68 commented 2 years ago

Hi @w00fz, thanks so much - it's obvious now you've told me! I had got as far as finding them in the header but I'd forgotten about grav.uri.getAllHeaders - that's just made my life so much easier! As a (very) part-time coder I can get stuck on quite simple problems.

w00fz commented 2 years ago

It’s all good, we all love simple solutions!