Random redirecting...

element94

Junior Member
Joined
Mar 14, 2008
Messages
144
Reaction score
17
Is there a way to make a page redirect to a random url from several given ?
 
Never mind i figured it out :

<script type="text/javascript">

var urls = new Array("http://www.url1.com/", "http://www.url2.com/");

function redirect()
{
window.location = urls[Math.floor(urls.length*Math.random())];
}

var temp = setInterval("redirect()", 3000);

</script>
 
Yep, but this will work only if javascript is enabled.

I'd rather do it in php, with meta refresh :

<?
$urls[]="http://www.url1.com/";
$urls[]="http://www.url2.com/";
//Add as many urls as you want this way
$rnd=rand(0,count($urls)-1);
$redirect=$url[$rnd];
echo "<html><head><meta http-equiv='refresh' content='0;url=".$redirect."'></head><body></body></html>";
?>

hope this helps ;)
 
Yep, but this will work only if javascript is enabled.

I'd rather do it in php, with meta refresh :

<?
$urls[]="http://www.url1.com/";
$urls[]="http://www.url2.com/";
//Add as many urls as you want this way
$rnd=rand(0,count($urls)-1);
$redirect=$url[$rnd];
echo "<html><head><meta http-equiv='refresh' content='0;url=".$redirect."'></head><body></body></html>";
?>

hope this helps ;)

Thanks for this one. Is there a way to show google.com or whatever as ref url ?
 
I'm not sure whether that would be possible or not to change the ref url. Anyway I'm sorry I have no idea how you could do this...
 
Using that code above from Zak_A above my browser gets stuck in an endless loop. I am running php4 I believe, can anyone help plz?
 
Hi

I think (please correct me if i;m wrong) there was a typo in Zak's code,

and it should have been

$redirect=$urls[$rnd];

instead of

$redirect=$url[$rnd];



but in any case, i'm still getting this error:

[h=1]Not Found[/h] The requested URL /.$redirect. was not found on this server.

- the link i was placing is a full url to a different website


ideas/suggestions ?
 
Back
Top