1 回答
TA贡献2065条经验 获得超14个赞
这将实现你所追求的。它利用 php 会话来跟踪您要重定向到的号码。
<?php
session_start();
// Check whether you've already redirected a user and if not, create a random number between min and max
$MIN = 1;
$MAX = 5127;
$rand = $_SESSION['last_redirect'] ?? rand($MIN,$MAX);
// Check whether you're within 10 of the maximum or not and if so, generate a new random number, if not add 10 on.
$rand = ($rand <= ($MAX-10)) ? $rand+10 : rand($MIN,$MAX);
// Store the value in a session for the next time the page is loaded
$_SESSION['last_redirect'] = $rand;
// Redirect ...
$redirect_to = 'https://example.net/'.$rand;
header("refresh:0; url=$redirect_to");
?>
这是一个实际的例子:
1) 导航到 php 页面:
2) 重定向到 example.net 并附加一个随机数:
3) 导航回 php 页面(第 1 步)并再次重定向但增加 10:
这将一直增加 10,直到您清除 php 页面的浏览历史记录(或取消设置会话变量),或者直到达到您指定的最大数量。一旦您在最大值的 10 以内,它就会生成一个新的随机数并将您重定向到该随机数。
- 1 回答
- 0 关注
- 81 浏览
添加回答
举报