Last active
March 16, 2020 12:16
-
-
Save ivuorinen/3644e9c514390d653a5104a974e9d700 to your computer and use it in GitHub Desktop.
Displays visitor IP
This file contains hidden or 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 getUserIpAddr() { | |
if(!empty($_SERVER['HTTP_CLIENT_IP'])){ | |
return $_SERVER['HTTP_CLIENT_IP']; | |
} | |
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ | |
return $_SERVER['HTTP_X_FORWARDED_FOR']; | |
} | |
return $_SERVER['REMOTE_ADDR']; | |
} | |
if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/^(curl|wget)/i', $_SERVER['HTTP_USER_AGENT'])) { | |
die(getUserIpAddr() . "\n"); | |
} | |
?><!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>IP-Osoite</title> | |
<style> | |
* { box-sizing: border-box; } | |
body { padding: 0px; margin: 0px; text-align: center; height: 100vh; font-family: monospace; font-size: 100%; } | |
.c1 { height: 100vh; align-content: space-around; align-items:center; display:flex; } | |
.c2 { flex: 1 1 0%; align-items:center; } | |
input { padding: 1rem; font-size: 3rem; text-align: center; border: 0px; } | |
</style> | |
</head> | |
<body> | |
<div class="c1"> | |
<div class="c2"> | |
<input | |
type="text" | |
onClick="this.setSelectionRange(0, this.value.length)" | |
readonly | |
value="<?php echo getUserIpAddr(); ?>"> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment