<?php
// 判断用户访问设备是否为移动设备
$isMobile = preg_match('/Mobi/i', $_SERVER['HTTP_USER_AGENT']);
// 随机选择图片链接文件
if ($isMobile) {
$file = '移动用户.txt'; // 移动设备访问的图片链接文件
} else {
$file = '电脑用户.txt'; // PC访问的图片链接文件
}
// 读取指定文件中的图片链接
$imageLinks = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// 随机选择一个图片链接
$randomImage = $imageLinks[array_rand($imageLinks)];
// 将图片直接输出
header('Content-Type: image/jpeg'); // 假设图片链接是 JPEG 格式,根据实际情况修改 MIME 类型
readfile($randomImage);
?>