Answer the question
In order to leave comments, you need to log in
Get and secure from spoofing a user's real IP from Cloudflare in Yii2?
Cloudflare uses Reverse Proxy, which makes it impossible to get the user's real IP through $request->userIP
, which disrupts the site, in particular, processing requests from payment systems.
The real IP is stored in the "CF-Connecting-IP" header. Yii2 has a function to change the IP acquisition mechanism: Trusted proxies and headers . But we are urged to fill trustedHosts
in, but it is not known in advance where Cloudflare will send data.
If you write a configuration, where only to list where to get headers for IP - everything works "as it should":
'request' => [
// ...
'ipHeaders' => [
'CF-Connecting-IP',
'X-Forwarded-For',
],
]
Answer the question
In order to leave comments, you need to log in
There is such a thing as real ip
https://support.cloudflare.com/hc/en-us/articles/2...
And the ip will be processed correctly, including the user's real ip in the logs
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question