Skip to content

Instantly share code, notes, and snippets.

@binarybucks
Created September 14, 2014 16:24
Show Gist options
  • Save binarybucks/3e30b0a487a5f1efbedf to your computer and use it in GitHub Desktop.
Save binarybucks/3e30b0a487a5f1efbedf to your computer and use it in GitHub Desktop.
little page to return current ip and user agent
<?php
if ($_SERVER["HTTP_X_FORWARDED_FOR"] != "") {
$IP = $_SERVER["HTTP_X_FORWARDED_FOR"];
$host = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]);
} else {
$IP = $_SERVER["REMOTE_ADDR"];
$host = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
}
header('Content-Type: application/json');
echo json_encode(array('ip' => $IP, 'host' => $host, 'userAgent' => $_SERVER["HTTP_USER_AGENT"]), JSON_PRETTY_PRINT);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment