Laravel offers a function called $request->ip() (instance of Illuminate/Http/Request). This function is very useful. In the API documentation (https://laravel.com/api/8.x/Illuminate/Http/Request.html#method_ips) I have now seen that there is also the function ips(). This is supposed to return the IP addresses to the clients. This surprises me. I thought there was always only one client IP. How can it be that this function exists? And I'm sure I'm missing something and Laravel has a reason to offer this function. I don't know what it is. I have also tried the function and get an array with only one IP.
CodePudding user response:
This method adds original and proxy chain IP's from X-Forwarded-For header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
CodePudding user response:
In a request, there may be more than one IP address such as in instances where a proxy is involved. The $request->ip() function attempts to return the ip address the request originated from using the X-FORWARDED-FOR header. The $request->ips() function attempts to return all IP addresses for a request which would include proxies if they have been involve d.
Have a look at the Symfony HttpFoundation Request source code for more information.
