Reputation: 313
I'm trying to redirect 2 URL randomly but it not working.
My Code
<?php
$urls=readStack();
if(empty($urls)) {
$urls = shuffle(array('https://domain1.com', 'https://domain2.com'));
$url=array_pop($urls);
storeStack($urls);
header('Location:' .$url);
?>
Help how to fix this?
Upvotes: 0
Views: 164
Reputation: 667
I don't know what readStack()
and storeStack()
are but you probably want something like
$arr = array('https://domain1.com', 'https://domain2.com');
shuffle($arr); // This returns a boolean and the array is modified inside the function so just pass in the array
$url=array_pop($arr); // Pop the top most element from the array and store into $url
header("Location: $url");
That code alone gives you a random url from those two
Upvotes: 1