Skip to content

Instantly share code, notes, and snippets.

@sdiama
Created May 20, 2021 08:43
Show Gist options
  • Save sdiama/c9bba52ea83db04885377de592283248 to your computer and use it in GitHub Desktop.
Save sdiama/c9bba52ea83db04885377de592283248 to your computer and use it in GitHub Desktop.
Get Real Client IP Behind Cloudflare in Laravel
/*
* @ 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