0

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?

johannchopin
  • 13,720
  • 10
  • 55
  • 101
Stellan Coder
  • 323
  • 1
  • 11

1 Answers1

1

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

xxMrPHDxx
  • 657
  • 5
  • 11