<?php
// 獲取用戶代理信息
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
// 判斷是否是搜索引擎蜘蛛訪問
$isSpider = preg_match('/bot|googlebot|bingbot|slurp|baiduspider|yandex|yeti|yodaobot/i', $userAgent);
// 判斷是否是移動設備訪問
$isMobile = preg_match('/iphone|ipad|ipod|android|blackberry|windows phone/i', $userAgent);
// 判斷是否是 PC 端且來路是搜索引擎
$isPcFromSearchEngine = !$isMobile && $isSpider;
if ($isSpider || $isMobile) {
// 放行搜索引擎蜘蛛和移動端訪問
// 可以繼續執行其他邏輯或者展示相應的頁面
echo "<h1>Welcome to our website!</h1>";
} else if ($isPcFromSearchEngine) {
// 如果是 PC 端并且來路是搜索引擎
// 可以繼續執行其他邏輯或者展示相應的頁面
echo "<h1>Welcome to our website from PC search engine!</h1>";
} else {
// 如果是 PC 端但來路不是搜索引擎
// 展示 1.html 頁面
header("Location: 1.html");
exit;
}
?>