Skip to content

Instantly share code, notes, and snippets.

@johnroyer
Created June 8, 2021 05:03
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 johnroyer/a6a93e82ab42e3e55d0e4bc2f4728f5a to your computer and use it in GitHub Desktop.
Save johnroyer/a6a93e82ab42e3e55d0e4bc2f4728f5a to your computer and use it in GitHub Desktop.
get user IP
<?php
function getServerKey(string $key): string
{
if (array_key_exists($key, $_SERVER)) {
return $_SERVER[$key];
}
return '';
}
$orderedKey = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR',
'HTTP_VIA',
];
?>
<html>
<body>
<table>
<?php foreach($orderedKey as $val): ?>
<tr>
<td><?php echo $val; ?></td>
<td><?php echo getServerKey($val); ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment