Random.php进入随机链接?

时间:2014-10-01 16:41:34

标签: php random

基本上,我试图创建一个random.php页面,如果有人继续使用它,它会将它们重定向到我想要的特定链接,并且每次他们继续使用随机链接.php将会有一个不同的链接例如......

$urls = array('http://gamingwebsite.com/xlnc', 'http://gamingwebsite.com/xln8', 'http://gamingwebsite.com/xln5', 'http://gamingwebsite.com/xln4', 
'http://gamingwebsite.com/xlmv', 'http://gamingwebsite.com/xlms', 'http://gamingwebsite.com/xllz', 'http://gamingwebsite.com/xllp', 'http://gamingwebsite.com/xllj', 
'http://gamingwebsite.com/xlle', 'http://gamingwebsite.com/xll9', 'http://gamingwebsite.com/xll5', 'http://gamingwebsite.com/xlks', 'http://gamingwebsite.com/xlkl', 
'http://gamingwebsite.com/xlke', 'http://gamingwebsite.com/xlk4', 'http://gamingwebsite.com/xljv', 'http://gamingwebsite.com/xlje', 'http://gamingwebsite.com/xlj9', 
'http://gamingwebsite.com/xlj1', 'http://gamingwebsite.com/xjxu', 'http://gamingwebsite.com/xjxd', 'http://gamingwebsite.com/xjx4', 'http://gamingwebsite.com/xjwz', 
'http://gamingwebsite.com/xjw1', 'http://gamingwebsite.com/xjup', 'http://gamingwebsite.com/xjtz', 'http://gamingwebsite.com/xjtt', 'http://gamingwebsite.com/xjtn', 
'http://gamingwebsite.com/xjrh', 'http://gamingwebsite.com/xjrd', 'http://gamingwebsite.com/xjr3', 'http://gamingwebsite.com/xj1z', 'http://gamingwebsite.com/xizx', 
'http://gamingwebsite.com/xizf', ' http://gamingwebsite.com/x3jx', 'http://gamingwebsite.com/x3jp');

这就是我所做的事情,我怎么能这样做,每当有人继续使用random.php它会将它们重定向到其中一个链接?

2 个答案:

答案 0 :(得分:3)

多种方式。一种简单的方法是使用rand()count()

的组合
header('Location:'. $urls[rand(0, (count($urls)-1))]);

或使用array_rand()

header('Location:'. $urls[array_rand($urls, 1)]);

答案 1 :(得分:3)

易。只需使用shuffle对数组进行随机播放,然后从新随机数组顶部抓取第一项,并通过header设置新的Location

shuffle($urls);
header('Location: ' . $urls[0]);