Last active
February 19, 2021 18:09
-
-
Save dale-c-anderson/6e9b2f2472be6fc48b6a5757a7f6f33d to your computer and use it in GitHub Desktop.
A php page that simply spits out the IP address of the visitor. Served as plain text for terminal (curl), HTML for browsers.
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 | |
/** | |
################## | |
ip.php | |
################## | |
A php page that simply displays the IP address of the visitor. | |
Serves plain text by default, serves a pretty html version by request, or if | |
the user agent string contains "Mozilla/", which is a pretty good indicator that the | |
request is coming from a web browser. | |
If Curl users are getting HTML in their terminal, check to make sure they dont have | |
a custom user agent string specified in their ~/.curlrc file. | |
*/ | |
$pretty = FALSE; | |
$agent = $_SERVER["HTTP_USER_AGENT"]; | |
if (isset($_GET["pretty"]) | |
|| stripos($_SERVER["REQUEST_URI"], "pretty") !== FALSE | |
|| stripos($agent, 'Mozilla/') !== FALSE | |
) { | |
$pretty = TRUE; | |
} | |
if ($pretty) { | |
?><!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Your IP Address</title> | |
<style> | |
body { | |
font-size: 200%; | |
padding: 20px; | |
} | |
input { | |
font-size: 40px; | |
} | |
main { | |
margin-top: 60px; | |
position: relative; | |
} | |
main div { | |
transform: translate(-50%, -50%); | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
} | |
</style> | |
</head> | |
<body> | |
<main> | |
<div> | |
<form> | |
Your IP address is:<br> | |
<input value="<?php echo $_SERVER["REMOTE_ADDR"]; ?>" onclick="this.select();" /> | |
</form> | |
</div> | |
</main> | |
</body> | |
</html><?php | |
} | |
else { | |
echo $_SERVER["REMOTE_ADDR"] . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment