akrabat / ip-address-middleware

PSR-7 Middleware that determines the client IP address and stores it as an ServerRequest attribute
Other
168 stars 38 forks source link

Capturing any IP #8

Closed wuno closed 7 years ago

wuno commented 7 years ago

Maybe I am missing the point. But my goal is to capture any IP from any request made to my rest api so I can keep track of them in a database.

I am using Slim 3 and when I use composer to load the middleware I use it like this and it always returns null from my localhost.

require '../vendor/autoload.php';

$app->get('/api/v1/customer', function (Request $request, Response $response) {
    $requestIP = $request->getAttribute('ip_address');
     var_dump($requestIP);
     echo $requestIP;

    return $response;
});

From my understanding this is options if you only want to accept request from certain IP,

$checkProxyHeaders = true; // Note: Never trust the IP address for security processes!
$trustedProxies = ['10.0.0.1', '10.0.0.2']; // Note: Never trust the IP address for security processes!
$app->add(new RKA\Middleware\IpAddress($checkProxyHeaders, $trustedProxies));

When I add that into my app the output is this,

string(3) "::1" ::1

If I am trying to capture the IP from the request is that $trustedProxies optional? If it is not optional how can I accept request from all IP?

To achieve my goal what am I missing here? Or am I getting the expected result and I just do not realize it?

wuno commented 7 years ago

Sorry I realize now I am an idiot and that is the loopback address, also that I need to call

$app->add(new RKA\Middleware\IpAddress());

Without any params.

If I am wrong please let me know.