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 關注
- 104 瀏覽
添加回答
舉報