Serves the same fields and formats as the old PHP scripts, with HTML/XML/CSV output escaped, X-Real-IP trusted only from loopback, and a 2s reverse-DNS timeout. m.z.gd becomes an nginx return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
$data = array (
|
|
'ip' => $_SERVER['REMOTE_ADDR'],
|
|
'hostname' => gethostbyaddr($_SERVER['REMOTE_ADDR']),
|
|
'user-agent' => (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''),
|
|
'timestamp' => time()
|
|
);
|
|
|
|
$output = (isset($_GET['output']) ? $_GET['output'] : '');
|
|
|
|
switch($output)
|
|
{
|
|
case 'xml':
|
|
header("Content-Type: text/xml");
|
|
echo '<?xml version="1.0"?>'."\n";
|
|
echo '<info>'."\n";
|
|
foreach($data as $key => $value)
|
|
echo "\t".'<'.$key.'>'.$value.'</'.$key.'>'."\n";
|
|
echo '</info>';
|
|
break;
|
|
case 'json':
|
|
header("Content-Type: application/json");
|
|
echo json_encode($data);
|
|
break;
|
|
case 'csv':
|
|
header("Content-Type: text/csv");
|
|
echo implode(',',$data);
|
|
break;
|
|
case 'txt':
|
|
default:
|
|
header("Content-Type: text/plain");
|
|
echo implode("\n",$data);
|
|
break;
|
|
}
|