Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created April 18, 2022 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcorrea/e0b4399e57c2639dd351d623668747b6 to your computer and use it in GitHub Desktop.
Save wilcorrea/e0b4399e57c2639dd351d623668747b6 to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('getClientAddress')) {
/**
* @return string|null
*/
function getClientAddress(): ?string
{
return $_SERVER['HTTP_CLIENT_IP']
?? $_SERVER['HTTP_X_FORWARDED_FOR']
?? $_SERVER['HTTP_X_FORWARDED']
?? $_SERVER['HTTP_FORWARDED_FOR']
?? $_SERVER['HTTP_FORWARDED']
?? $_SERVER['REMOTE_ADDR']
?? null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment