Laravel 透過request()->ip拿到的ip不是client real ip,原來是因為前面有一層cloudflare,解決方法如下,改用下面這段script來取ip: 可以包成helper function方便使用。 值得一提的是,HTTP_CF_CONNECTING_IP有可能是偽造的,可以從$_SERVER['REMOTE_ADDR'] 檢查裡面是否有從cloudflare來的ip,詳請可參考:https://thisinterestsme.com/php-ip-address-cloudflare/ 本筆記參考:1. https://panjeh.medium.com/laravel-cloudflare-logging-real-visitor-ip-address-server-solution-1e9739e896542. https://laracasts.com/discuss/channels/laravel/cloudflare-and-user-ip3. https://qiita.com/ziming/items/575355bdf383b1ec4d924. https://stackoverflow.com/questions/60777969/request-ip-in-laravel-application-not-correct5. https://khalilst.medium.com/get-real-client-ip-behind-cloudflare-in-laravel-189cb89059ff6. https://thisinterestsme.com/php-ip-address-cloudflare/