百度搜尋結果連結常為 https://www.baidu.com/link?url=加密字串 形式,點擊會經 301/302 重導向至真實網址。本工具可解析最終落地 URL 並提取加密參數。
<?php
/**
* 取得最終重導向網址
* @param string $url 百度 link 連結
* @return string 最終 URL
*/
function getRealUrl($url) {
$headers = @get_headers($url, 1); // 1 = 關聯陣列格式
if ($headers === false) return $url; // 連線失敗回傳原網址
$statusLine = $headers[0] ?? '';
if (stripos($statusLine, '301') !== false || stripos($statusLine, '302') !== false) {
$location = $headers['Location'] ?? '';
// Location 可能為陣列 (多次重導向),取最後一個
if (is_array($location)) {
return end($location);
}
return $location ?: $url;
}
return $url;
}
// 處理表單提交
$inputForm = '<form method="get"><input type="text" name="url" placeholder="貼上百度 link 連結" style="width:80%; padding:8px;"> <button type="submit">解析</button></form>';
$url = $_GET['url'] ?? '';
if (!$url) {
exit($inputForm);
}
$realUrl = getRealUrl($url);
echo "<p>真實網址: <a href='" . htmlspecialchars($realUrl) . "' target='_blank'>" . htmlspecialchars($realUrl) . "</a></p>";
// 提取百度加密參數 (ebac5573358cc3c0659257bfcf54 + hex)
$realUrlClean = ltrim($realUrl, 'https://');
if (preg_match('/ebac5573358cc3c0659257bfcf54([0-9a-f]+)/i', $realUrlClean, $m)) {
$encoded = $m[1];
echo "<p>加密段落: " . htmlspecialchars($encoded) . "</p>";
// 簡單視覺化對應 (僅供參考,非真實解密演算法)
$urlChars = str_split($realUrlClean);
$encPairs = str_split($encoded, 2);
echo "<p>字元對應參考 (非解密):</small><br><code>";
foreach ($encPairs as $i => $pair) {
echo htmlspecialchars(($urlChars[$i] ?? '?') . '→' . $pair) . ' ';
}
echo "</code></p>";
}
echo $inputForm;
?>
baidu_link_parser.php 部署至 PHP 環境。link?url=... 連結。get_headers() 預設使用 GET 請求並自動追蹤重導向 (PHP 7.1+),第二參數 1 回傳關聯陣列便於取 Location。curl_multi 並發請求。僅供個人學習研究使用,請勿用於大規模爬蟲、流量劫持或任何違反《網絡安全法》及百度服務條款的行為。