Created
May 20, 2021 08:43
-
-
Save sdiama/c9bba52ea83db04885377de592283248 to your computer and use it in GitHub Desktop.
Get Real Client IP Behind Cloudflare in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @ AppServiceProvider add... | |
*/ | |
use Symfony\Component\HttpFoundation\Request; | |
public function boot() { | |
/* This line set the Cloudflare's IP as a trusted proxy | |
Request::setTrustedProxies( | |
['REMOTE_ADDR'], | |
Request::HEADER_X_FORWARDED_FOR | |
); | |
} | |
/* | |
* When calling request()->ip or requset()->getClientIp() the real IP will be returned | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment