Skip to content

Commit

Permalink
correct IP on Cloud Run
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacarpet committed Sep 26, 2024
1 parent 9cee4f7 commit 80db243
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_APPENGINE_USER_IP'];
} elseif (is_cloud_run()) {
$forwards = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = trim(array_pop($forwards));
array_reverse($forwards);
// try 2nd entry first, as 1st is usually GCLB.
$_SERVER['REMOTE_ADDR'] = trim($forwards[1] ?? $forwards[0]);
}
if (!empty($_SERVER['HTTP_X_APPENGINE_HTTPS'])) {
// Turn HTTPS on for Laravel
Expand Down

0 comments on commit 80db243

Please sign in to comment.