Created
September 23, 2016 17:15
-
-
Save ljungmark/482049a8df94f33fdce5501a7c36f289 to your computer and use it in GitHub Desktop.
Convert a UA provided IPv4-address to it's hexadecimal value
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 ip4_to_hex($ip_address = null) { | |
if ($ip_address === null || filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) return 'Unable to read IP address'; | |
$fragments = explode('.', $ip_address); | |
return sprintf('%02x%02x%02x%02x', $fragments[0], $fragments[1], $fragments[2], $fragments[3]); | |
} | |
print ip4_to_hex($_SERVER['REMOTE_ADDR']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment