Ikechukwu
Ikechukwu

Reputation: 1145

Laravel 8: Get server IP address when using an HTTP Client

I'm utilizing the new HTTP Client within the Laravel 8 framework, which I use to call my APIs for certain micro-services.

How can I attain the Server IP of each sender when I receive a response? All of my clients are specifically client websites hosted on various servers online.

Here's a sample function:

$response = Http::post('https://example.com', [
    'id' => $id
]);

EDIT: https://example.com is my server. I need the Server IP of the Clients sending the requests.

Upvotes: 1

Views: 13605

Answers (1)

Bruno
Bruno

Reputation: 101

Laravel has a function in its api :

Request::ip();

from which you can get the client ip from his request on your application or you can use php methods to access client ip in array of $_SERVER[] as :

$_SERVER['REMOTE_ADDR']

Upvotes: 5

Related Questions