A simple PHP script to tell a visitor's IP address and more information. Similar to ipecho.net/plain, but better :)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

<?php
$config = include('config.php');
// Define method by get parameter
if(empty($_GET)) {
$method = "simple";
} else {
$method = $_GET['m'];
}
if($method === "simple") { // simple
echo $_SERVER['REMOTE_ADDR'] . "\n";
} elseif($method === "detailed" ) { // detailed
readheader("REMOTE_ADDR");
readheader("HTTP_X_FORWARDED_FOR");
readheader("HTTP_USER_AGENT");
readheader("HTTP_CLIENT_IP");
readheader("HTTP_X_FORWARDED");
readheader("HTTP_FORWARDED_FOR");
readheader("HTTP_FORWARDED");
readheader("HTTP_HOST");
readheader("HTTP_URI");
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo "<br />";
echo "<strong>HOSTNAME</strong>: " . $hostname;
echo "<br />";
echo "<strong>IPv4 REVERSE LOOKUP</strong>: " . implode(', ', gethostbynamel($hostname));
echo "<br /><br />";
echo 'Plain IP address: <a href="//'.$config->ip4domain.'">IPv4</a> | <a href="//'.$config->ip6domain.'">IPv6</a>';
echo "<br />";
echo 'Detailed header info: <a href="//'.$config->ip4domain.'/'.$config->detailed_uri.'">IPv4</a> | <a href="//'.$config->ip6domain.'/'.$config->detailed_uri.'">IPv6</a>';
} else { // wrong URL
header("HTTP/1.1 301 Moved Permanently");
header("Location:/".$config->detailed_uri."");
exit;
}
function readheader($value)
{
echo "<strong>" . $value . "</strong>: "; // show desired value
if(isset($_SERVER[$value])) { // only if desired header has been delivered
echo $_SERVER[$value];
}
echo "<br />";
}
?>