Google PageRank(PR)雖已停止公開更新,但作為「網站權重」的經典指標,仍被許多站長作為參考。與其依賴第三方在線工具(廣告多、限頻、數據舊),不如花幾分鐘部屬一個屬於自己的查詢頁——整合 PR、WHOIS、Alexa 排名、Google/Baidu site:link: 收錄查詢,甚至順帶查詢域名對應 IP,一頁搞定。
$url = $_POST['url'] ?? '';
$prApi = "https://www.getyourpagerank.com/rank.php?url=" . urlencode($url);
$html = @file_get_contents($prApi);
preg_match('/PageRank:\s*(\d+)/i', $html, $m);
$pr = $m[1] ?? 'N/A';
注意:該接口已不穩定,現代替代方案可改用第三方 SEO API(如 Moz、Ahrefs、SEMrush)或自建基於歷史數據的查詢庫。
$domain = parse_url($url, PHP_URL_HOST) ?? $url;
$domain = preg_replace('/^www\./', '', $domain);
$whoisUrl = "https://whois.domaintools.com/{$domain}";
$alexaUrl = "https://alexa.chinaz.com/?domain=" . urlencode($url);
$googleLink = "https://www.google.com/search?q=link:" . urlencode($url);
$googleSite = "https://www.google.com/search?q=site:" . urlencode($url);
$baiduLink = "https://www.baidu.com/s?wd=link:" . urlencode($url);
$baiduSite = "https://www.baidu.com/s?wd=site:" . urlencode($url);
$ip = gethostbyname($domain); // 同步阻塞,生產建議異步或緩存
<?php
$url = $_POST['url'] ?? '';
$pr = $domain = $ip = '';
$showForm = true;
if ($url) {
$showForm = false;
// 1. 規範化 URL
if (!preg_match('/^https?:\/\//i', $url)) $url = 'https://' . $url;
$domain = parse_url($url, PHP_URL_HOST) ?: $url;
$domain = preg_replace('/^www\./', '', $domain);
// 2. 獲取 PR(示例接口,實際請替換)
$prHtml = @file_get_contents("https://www.getyourpagerank.com/rank.php?url=" . urlencode($url));
preg_match('/PageRank:\s*(\d+)/i', $prHtml, $m);
$pr = $m[1] ?? '未知';
// 3. 解析 IP
$ip = gethostbyname($domain);
}
?>
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>PR 綜合查詢</title>
<style>body{font-family:system-ui,sans-serif;max-width:800px;margin:2rem auto;padding:0 1rem} input[type=text]{width:70%;padding:.5rem} button{padding:.5rem 1.2rem} .result{margin-top:1.5rem;line-height:2} .label{font-weight:bold;color:#333} a{color:#0066cc} </style></head><body>
<h1>🔍 網站綜合 SEO 信息查詢</h1>
<form method="post">
<input type="text" name="url" placeholder="輸入域名或完整 URL,例:example.com" required value="<?= htmlspecialchars($url) ?>">
<button type="submit">查詢</button>
</form>
<?php if (!$showForm): ?>
<div class="result">
<p><span class="label">查詢地址:</span> <a href="<?= htmlspecialchars($url) ?>" target="_blank"><?= htmlspecialchars($url) ?></a></p>
<p><span class="label">PageRank:</span> <strong><?= $pr ?></strong></p>
<p><span class="label">域名:</span> <?= htmlspecialchars($domain) ?></p>
<p><span class="label">解析 IP:</span> <?= htmlspecialchars($ip) ?> <a href="https://whois.domaintools.com/<?= urlencode($domain) ?>" target="_blank">[WHOIS]</a></p>
<p><span class="label">Alexa 排名:</span> <a href="https://alexa.chinaz.com/?domain=<?= urlencode($url) ?>" target="_blank">查看</a></p>
<p><span class="label">Google 收錄:</span>
<a href="<?= $googleSite ?>" target="_blank">site:</a> |
<a href="<?= $googleLink ?>" target="_blank">link:</a>
</p>
<p><span class="label">百度收錄:</span>
<a href="<?= $baiduSite ?>" target="_blank">site:</a> |
<a href="<?= $baiduLink ?>" target="_blank">link:</a>
</p>
</div>
<?php endif; ?>
</body></html>
curl_multi 或 Swoole 並發查詢 PR、WHOIS、Alexa、IP,大幅降低頁面等待時間。一個 pr_query.php,幾十行代碼,即可擁有專屬的站長工具箱。既能滿足日常查詢,又能作為學習 HTTP 請求、正則提取、域名解析、前後端分離 的絕佳練手項目。動手試試吧!