PDA

View Full Version : Random Page script?



completely
05-04-2006, 12:31 PM
You know the way you can have a random image script?

Where it selects an image at random out of the list of them which you have put into the php file, is it possible to do this, but with a page.

So, A random Page script.

I want this so i can have various adverts on my page for different pages on my site.

timROGERS
05-04-2006, 12:48 PM
Yeah


<?php
$number = rand(1, 3);
if ($number = 1)
header("Location: 1stpage.php");
if ($number = 2)
header("Location: 2ndpage.php");
if ($number = 3)
header("Location: 3rdpage.php");
?>

completely
05-04-2006, 01:05 PM
Thanks alot mate :)

nets
05-04-2006, 05:20 PM
If you don't have PHP support.

<script type="text/JavaScript">
<!--Begin
var pages = new Array('page1.htm','page2.htm','page3.htm');

function rand_page() {
var rand_num;
rand_num = Number(Math.floor(Math.random()*pages.length));
return pages[rand_num];
}

document.location.href = rand_page();
//-->
</script>

That should work, but I haven't tested it (I might've made a typo).

Want to hide these adverts? Register an account for free!