Tiny PHP “Health Check” Page (drop-in)
PHP Site Health Check (IP + Time + HTTPS + PHP Version)
#php #tools #webmaster #diagnostics
This is a tiny “is everything alive?” page you can drop onto any site to confirm PHP is running and see basic request/server info.
What it shows:
- Your IP address
- Server time
- Whether HTTPS is on
- PHP version
- Hostname + User-Agent (trimmed)
How to use:
1) Save as /health.php
2) Visit https://yoursite.com/health.php
Optional: add ?json=1 for a JSON response.
Notes:
- No external requests
- No file writes
- No database
- AdSense-safe wording (no adult terms)
<?php
declare(strict_types=1);
header('X-Content-Type-Options: nosniff');
function h(string $s): string {
return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
$ip = (string)($_SERVER['REMOTE_ADDR'] ?? '');
$ua = (string)($_SERVER['HTTP_USER_AGENT'] ?? '');
$ua = mb_substr($ua, 0, 180, 'UTF-8');
$https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'yes' : 'no';
$data = [
'ok' => true,
'ip' => $ip,
'server_time' => date('Y-m-d H:i:s'),
'https' => $https,
'php' => PHP_VERSION,
'host' => (string) gethostname(),
'ua' => $ua,
];
if (isset($_GET['json'])) {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
header('Content-Type: text/html; charset=UTF-8');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Health Check</title>
</head>
<body>
<h1>✅ Health Check</h1>
<p>If you can see this page, PHP is working.</p>
<ul>
<li><b>IP:</b> <code><?= h($data['ip']) ?></code></li>
<li><b>Server time:</b> <code><?= h($data['server_time']) ?></code></li>
<li><b>HTTPS:</b> <code><?= h($data['https']) ?></code></li>
<li><b>PHP:</b> <code><?= h($data['php']) ?></code></li>
<li><b>Host:</b> <code><?= h($data['host']) ?></code></li>
<li><b>User-Agent:</b> <code><?= h($data['ua']) ?></code></li>
</ul>
<p>JSON mode: add <code>?json=1</code></p>
</body>
</html>
Comments (0)
No comments yet — be the first.