PDA

View Full Version : Random homepage


rasmits
2005-12-18, 20:46
Let's say I have 4 or 5 versions of the same homepage, how can I randomize it so when a user enters the address, there are a couple options as to what they'll see?

chucker
2005-12-18, 20:48
You'll need server-side scripting, such as PHP, to do that.

Brad
2005-12-18, 20:49
Or JavaScript if you don't mind forwarding the person to another page.

chucker
2005-12-18, 20:50
True. Either way, it's rather simple to pull off. Of course, I'm a lazy bum and won't say how.

Brad
2005-12-18, 20:54
:lol: Yeah, ditto. That's what Google's for.

rasmits
2005-12-18, 21:10
Well, I guess it's not that important, I was just wondering. Thanks anyway.

Brad
2005-12-18, 21:11
Well, here... I'll move this thread over to the Programmer's Nook where you may get a better response. :)

Chinney
2005-12-18, 21:20
Interesting idea Rasmits. But when I saw the title of this thread - and before I saw what you actually meant by the title - my mind immediately jumped to another interesting idea: being able to program your browser so that every time you opened it, it took you to a random place on the internet. I like that idea. You might want to set a few parameters in advance with respect to content (or not!). Broaden your horizons.

rasmits
2005-12-18, 21:38
Thats a cool idea too, though, 90% of the results wouldn't be very flattering.

Brad
2005-12-18, 21:53
Well, here's a quick and dirty way of doing what I think you want, rasmits.

<?php
$pages = array("index1.html","index2.html","index3.html","index4.html");
$destination = rand(0,sizeof($pages)-1);
header("Location:".$pages[$destination]);
?>

Save that as index.php and it'll redirect the visitor to one of the links in the $pages array. Be sure you don't have anything before the opening "<?php" otherwise the redirect will fail.

If you want the random page to appear to be at this location (ie. the user won't see a redirect and won't see the URL of the random pages), change it to work like this:

<?php
$pages = array("index1.html","index2.html","index3.html","index4.html");
$destination = rand(0,sizeof($pages)-1);
include $pages[$destination];
?>

rasmits
2005-12-18, 23:02
Awesome, thank you very much.