我在一个文件中有 10 个网址。
我想将每个网址显示 10 分钟,完成后重新开始。
<?php
$version = "v1.01";
$linksfile = "urlrotator.txt";
$urls = file("$linksfile");
$url = rand(0, sizeof($urls) - 1);
$goto = "$urls[$url]";
header("Location: $goto");
这只是随机旋转。
需要根据时间
urlrotator.txt
内容如下
nr1.html
nr2.html
nr3.html
nr4.html
nr5.html
nr6.html
nr7.html
nr8.html
nr9.html
nr10.html
您可以使用
time
函数查找当前秒,并从中查找当前 10 分钟的块。然后根据您拥有的 URL 数量使用模求余数。
$minutesBetweenChanges = 10;
$urls = file('urlrotator.txt');
$numberOfURLs = count($urls);
$selection = (int) ((time() / 60) / $minutesBetweenChanges) % $numberOfURLs;
header('Location: ' . $urls[$selection]);
谢谢...
因此,如果我在文件中有 100 个 url,我是否需要更改脚本中的任何内容