Created
June 8, 2021 05:03
-
-
Save johnroyer/a6a93e82ab42e3e55d0e4bc2f4728f5a to your computer and use it in GitHub Desktop.
get user IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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