// 仅当访问非 url.whsc.gay 域名时执行以下代码
if (strpos($_SERVER['HTTP_HOST'], 'whsc.gay') === false) {
    $domains = explode(',', '213.qq.whsc.gay');
    $chosen_domain = $domains[array_rand($domains)]; // 随机获取$j46里的一个值

    if (!isset($_COOKIE['redirected'])) {
       setcookie('redirected', 'true', time()+10);
       $current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
       $new_url = 'http://' . $chosen_domain . $_SERVER['REQUEST_URI'];
       header('Refresh: 3; URL=' . $new_url);
       echo '<title>跳转中,请稍等 </title>
       <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
       <style>
           * {
               margin: 0;
               padding: 0;
               font-family: 'Microsoft YaHei';
               color: #fff;
           }
           
           body,
           div,
           form,
           input,
           li,
           ol,
           p,
           textarea,
           ul {
               margin: 0;
               padding: 0;
               font-family: 'Microsoft YaHei';
               color: #fff;
           }
           
           body {
               background: #fff;
               color: #3f3f3f;
               font-family: Apple LiGothic Medium, SimHei, Geneva, Arial, Helvetica, sans-serif;
               -webkit-tap-highlight-color: transparent;
               -webkit-tap-highlight-color: transparent;
               -webkit-touch-callout: none;
               -webkit-appearance: none;
               width: 100%;
               font-size: 12px;
           }
           
           body p {
               color: white;
               text-align: center;
               line-height: 25px;
           }
           
           .spinner {
               margin: 100px auto 0;
               width: 150px;
               text-align: center;
           }
           
           .spinner > div {
               width: 30px;
               height: 30px;
               background-color: #B0C4DE;
               border-radius: 100%;
               display: inline-block;
               -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
               animation: bouncedelay 1.4s infinite ease-in-out;
               /* Prevent first frame from flickering when animation starts */
               -webkit-animation-fill-mode: both;
               animation-fill-mode: both;
           }
           
           .spinner .bounce1 {
               -webkit-animation-delay: -0.32s;
               animation-delay: -0.32s;
           }
           
           .spinner .bounce2 {
               -webkit-animation-delay: -0.16s;
               animation-delay: -0.16s;
           }
           
           @-webkit-keyframes bouncedelay {
               0%, 80%, 100% {
                   -webkit-transform: scale(0.0)
               }
               40% {
                   -webkit-transform: scale(1.0)
               }
           }
           
           @keyframes bouncedelay {
               0%, 80%, 100% {
                   transform: scale(0.0);
                   -webkit-transform: scale(0.0);
               }
               40% {
                   transform: scale(1.0);
                   -webkit-transform: scale(1.0);
               }
           }
       </style>
       <div id='paneloading' style='display:'>
           <div class='spinner'>
               <div class='bounce1'></div>
               <div class='bounce2'></div>
               <div class='bounce3'></div>
           </div>
           <body style='background: #FFFFFF;'></body>
       </div>';
       exit();
    } else {
       // 已经跳转过,不再跳转
    }
}

代码说明:

  1. 判断域名: strpos($_SERVER['HTTP_HOST'], 'whsc.gay') === false 用于检查当前访问的域名是否包含 whsc.gay,如果不是,则执行后续代码。
  2. 随机域名选择: $chosen_domain = $domains[array_rand($domains)]; 从域名数组中随机选取一个域名。
  3. 跳转逻辑: 如果当前访问者没有设置 redirected cookie,则设置 cookie 并进行跳转,并显示跳转提示页面。
  4. 跳转提示页面: 使用 HTML 和 CSS 创建一个简单的跳转提示页面,并使用 header('Refresh: 3; URL=' . $new_url); 设置 3 秒后自动跳转到目标页面。

注意: 这段代码可能存在安全风险,例如:

  • 域名黑名单: 需要确保 $domains 数组中的域名是可靠的,避免恶意跳转。
  • Cookie 伪造: 攻击者可能通过伪造 cookie 来绕过跳转逻辑。

建议在实际应用中进行更全面的安全考虑,例如使用更安全的跳转机制和 cookie 管理方式。

SEO 优化:

  1. 标题: 使用更具描述性的标题,例如 '网站重定向脚本' 或 '随机域名跳转代码'。
  2. 描述: 简要介绍脚本的功能和用途。
  3. 关键字: 包含与脚本相关的关键词,例如 '域名跳转', '网站重定向', '随机跳转', 'PHP' 等。
  4. 内容: 使用更清晰的语言解释代码的逻辑,并添加一些代码示例和解释,方便用户理解和使用。

免责声明: 这段代码仅供参考,请根据自身需求进行修改和使用,并注意安全风险。

随机域名跳转 - 网站重定向

原文地址: https://www.cveoy.top/t/topic/buna 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录