发表于 2024/2/5 09:37:55
又一神奇产物
[PHP] 纯文本查看 复制代码
 // 判断是否是论坛帖子列表页 // $isForumdisplay = strpos($_SERVER['REQUEST_URI'], 'forum.php?mod=forumdisplay') !== false; // 判断首页 $isHomepage = ($_SERVER['REQUEST_URI'] == '/' || $_SERVER['REQUEST_URI'] == '/index.php'); // if (!isset($_G['visited_df_sort']) && $isForumdisplay) { if (!isset($_G['visited_df_sort']) && $isHomepage) { $_G['visited_df_sort'] = true; $visitCount = isset($_SESSION['visitCount']) ? intval($_SESSION['visitCount']) + 1 : 0; $_SESSION['visitCount'] = $visitCount; // 获取当前版块 fid $currentFid = 2; // 定义排序方式数组 $sortOptions = array( 0 => "/", 1 => "/forum.php?mod=forumdisplay&fid=2&filter=heat&orderby=heats", 2 => "/forum.php?mod=forumdisplay&fid=2&filter=reply&orderby=replies", 3 => "/forum.php?mod=forumdisplay&fid=2&filter=reply&orderby=views" ); // 根据访问次数选择排序方式 $sortUrl = ''; if ($visitCount < 4) { $sortUrl = $sortOptions[$visitCount]; } else { // 三次以后随机选择排序方式 $sortUrl = $sortOptions[array_rand($sortOptions)]; } // 避免无限循环,检查当前 URL 是否已经是选择的排序方式 $currentUrl = $_SERVER['REQUEST_URI']; if (strpos($currentUrl, $sortUrl) === false) { // 执行重定向 header_remove(); header("Location: $sortUrl"); exit(); } }
😂