2024-04-25
<?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;
}
?>

PHP 代码 实现引擎来路、蜘蛛、移动端放行

返回列表 返回列表