When using Cloudflare and Laravel we are unable to use
request()->ip() in Laravel because of Cloudflare returns it's own IP in
By default, Cloudflare acts as a reverse proxy (read more here) As such, all connections to your origin web server come from Cloudflare IP addresses, So there are some issues:
1- If your web application is using the originating IP of the visitor as part of its logic, it will now use a Cloudflare IP address instead
2- If you use the content of your access logs, they now contain a Cloudflare IP address as the $remote_addr
Solution 1: Code Manipulation
However, Cloudflare follows industry standards and includes the visitor’s IP address in the X-Forwarded-For header. It also add a CF-Connecting-IP header that may be used as well. You can use these headers to either restore the originating IP of your visitor for your web application or to be include it in your logs.
Solution 2: Server Solution
CloudFlare has release
mod_cloudflare for Apache, which logs & displays the actual visitor IP address rather than the CloudFlare IP address. So the solution is to install mod_cloudflare for Apache httpd as follow:
Manual Installation: RedHat / CentOS / CloudLinux
mod_cloudflare has a few software dependencies that need to be installed first:
# yum install libtool httpd-devel
Next, you should download the mod_cloudflare source to your server:
Finally, install the module. Depending on your system, the command to run might be apxs or apxs2. So, run one of the below two commands. If you get a ‘Command not found’ when running one, try the other:
# apxs -a -i -c mod_cloudflare.c# apxs2 -a -i -c mod_cloudflare.c
Thank you for reading! If you enjoyed this article:
Clap it ! Share it! Follow Me in Medium!
Panjeh — Medium
Read writing from Panjeh on Medium. Physicists PhD, Self-taught web developer #Learning, #laravelphp #Vuejs. Every day…
Also I’d like to hear your opinion on this article. If you have any doubt, question or suggestion please leave a comment below.
Have a very wonderful day!
Previous Stories You will Love:
Laravel call named routes in console internally php artisan command
How to call Laravel routes internally php artisan command
Telegram Bot Packages libraries Examples in Laravel, PHP, Node.js, Python, Java, Ruby, Swift, C++
If you want to learn more about Telegram bots, This Introduction to Bots would be a good guide to start.
Laravel Auth::routes() Email verification Reset password Authentication Registration routes
Auth::routes() is a helper class that helps you generate all the routes required for user authentication
Laravel eloquent model increment with or without updating timestamps
Problem: You may need to increment a field in a record of a table (Laravel Model) and do not want update the updated_at…
Laravel validation username no space allowed alpha_dash or regex custom rule
If you want to restrict the username in Laravel to only accept letters, numbers, dashes and underscores and not space…
Laravel delete queued jobs using redis horizon artisan command
The question is how to delete all jobs which are queued in Laravel when you are using redis as the Queue driver.
Laravel detector mobile browser name version platform device robot crawler user language
Laravel define global constants Config php file
If you look at the main Laravel directory you can find these subdirectories:
Laravel session flash message include html tag link href
In Laravel you may insert a or strong tags into the flash message deliver to the session.
Laravel 502 Bad Gateway when starting Laravel Valet — Simple solution
The first solution is here: