However, CF-Connecting-IP is not part of the visitor’s request, but it’s added by Cloudflare at the edge. Therefore it doesn’t seem to be available as part of the http.request.headers field. I’m not sure if there’s another field that contains its value.
In your browser you’d only see response headers. If you want to see what these fields contain on a test basis, you could create headers on your origin that echo back their content.
There’s a Managed Transform Rule to remove X-Forwarded-IP, make sure you haven’t enabled it.
Also, disable any rules you were creating to add X-Forwarded-IP header, as it may remove the original header even if it doesn’t add the one you want. For instance, if you try to add this header with the content of a dynamic field that’s empty, the header will not be created with an empty value. Instead, it won’t be created at all.
It works for me on a Free Plan, so you should check your PHP code to see if there’s something else at play that prevents it from seeing those request headers.
What I have that gives me confidence these headers are set is:
<If "%{QUERY_STRING} =~ /test.*?/">
# Testing if cf-connecting-ip is present
SetEnvIfNoCase CF-Connecting-IP (.*) CC_IP=$1
Header set A-CCI %{CC_IP}e
# Testing if x-forwarded-ip is present
SetEnvIfNoCase X-Forwarded-For (.*) XFF_IP=$1
Header set A-XFF %{XFF_IP}e
</If>
Then if I curl my website with:
curl -sI https://example.com/?test=1 | egrep 'a-'
I get:
a-cci: MY-IP
a-xff: MY-IP, CF-IP
You can try the same directives on your .htaccess, but it may or may not work depending on how your server is configured, and any further questions about that would fall outside the scope of this community. You may want to reach out to a server admin or PHP support forum.
Hey thank yo so much, I added that code into my htaccess and I made a curl.
I don’t know it it is okay, but the initial command didn’t work on my mac so I had to tweak it a bit (I asked chatgpt) : curl -sI "https://mywebsite.com/?test=1" | grep -e 'a-'
Yes, it is. Please see the link I posted above about these headers. Depending on certain conditions, both headers will have the same value.
That means both headers are being added to requests, as documented, and now as I said before you need to bring to the relevant forums (PHP, server admin) why your code isn’t recognizing them.