Skip to content

Commit

Permalink
Add remote IP handling in LaravelValetDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-chetan committed Nov 2, 2024
1 parent 4d3d64a commit 2d56e10
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/Valet/Drivers/LaravelValetDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ public function beforeLoading(string $sitePath, string $siteName, string $uri):
$_SERVER['PHP_SELF'] = $uri;
$_SERVER['SERVER_ADDR'] = $_SERVER['SERVER_ADDR'] ?? '127.0.0.1';
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['REMOTE_ADDR'] = $this->remoteIP();
}

public function remoteIP()
{
if ($_SERVER['HTTP_X_REAL_IP'] ?? false) {
return $_SERVER['HTTP_X_REAL_IP'];
}

if ($_SERVER['HTTP_X_FORWARDED_FOR'] ?? false) {
return explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0] ?? $_SERVER['REMOTE_ADDR'];
}

return $_SERVER['REMOTE_ADDR'];

}

/**
Expand Down

0 comments on commit 2d56e10

Please sign in to comment.