View Full Version : Random homepage
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?
You'll need server-side scripting, such as PHP, to do that.
Or JavaScript if you don't mind forwarding the person to another page.
True. Either way, it's rather simple to pull off. Of course, I'm a lazy bum and won't say how.
:lol: Yeah, ditto. That's what Google's for.
Well, I guess it's not that important, I was just wondering. Thanks anyway.
Well, here... I'll move this thread over to the Programmer's Nook where you may get a better response. :)
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.
Thats a cool idea too, though, 90% of the results wouldn't be very flattering.
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];
?>
Awesome, thank you very much.
vBulletin® v3.6.4, Copyright ©2000-2024, Jelsoft Enterprises Ltd.