加一个判断获取变量$j46里的域名后判断是否可以在QQ和微信内访问如果不可以提示无可用域名$j46 = $confj46;$j47 = $confj47;if $j47 == 1 $domains = explode $j46;$chosen_domain = $domainsarray_rand$domains; 随机获取$j46里的一个值if !isset$_COOKIEredirected
增加判断代码如下:
$j46 = $conf['j46']; $j47 = $conf['j47']; if ($j47 == 1) { $domains = explode(",", "$j46"); $available_domain = ''; // 可用域名 foreach ($domains as $domain) { $url_qq = "https://graph.qq.com"; $url_wechat = "https://open.weixin.qq.com"; $qq_status = checkDomainStatus($url_qq, $domain); $wechat_status = checkDomainStatus($url_wechat, $domain); if ($qq_status && $wechat_status) { $available_domain = $domain; break; } } if ($available_domain == '') { echo "无可用域名"; exit(); } if (!isset($_COOKIE['redirected'])) { setcookie('redirected', 'true', time()+10); $current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $new_url = "http://" . $available_domain . $_SERVER['REQUEST_URI']; header("Refresh: 2; URL=$new_url"); echo "嘿嘿"; exit(); } else { // 已经跳转过,不再跳转 } }
function checkDomainStatus($url, $domain) { $headers = @get_headers("$url", 1); if ($headers && isset($headers['Location'])) { if (is_array($headers['Location'])) { $location = $headers['Location'][0]; } else { $location = $headers['Location']; } $parsed_url = parse_url($location); if (isset($parsed_url['host']) && $parsed_url['host'] == $domain) { return true; } else { return false; } } else { return false; }
原文地址: https://www.cveoy.top/t/topic/eg6I 著作权归作者所有。请勿转载和采集!