Serving random page

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
ijese
Forum Members
Forum Members
Posts: 19
Joined: Sun May 14, 2006 2:36 pm

Serving random page

Post by ijese »

Hi all,

I need a way to serve 2 homepages, showing each 50% of the time. Is there a way to do it and how?

Thanks for reading this,
Igor

ps. I asked the same question before but probably the title wasn't motivating for anyone to read, so...
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

Re: Serving random page

Post by scooper »

One quick and dirty way to do it is just to define a tag to punt the user to a random page.

Soo... create a user defined tag called goRandomPage (or whatever you want to call it), with some code to pick a page based on a random number:

$goPage=(rand(1,2)==1) ?  "Home1" : "Home2";
header("Location: index.php?page=".$goPage);

Then put the new tag {goRandomPage} in a page. When it loads it will pick either the page 'Home1' or 'Home2' (obviously you can change those to the names of the different pages you want to use) and just load the new page (in this case 'index.php?page=Home1'  or 'index.php?page=Home2').

If you're using fancy url schemes then you'll have to change the way the page loads to match.

There. It's not pretty and there's probably a much nicer way to do it, but it works - and it's the best you'll get from me till I get some coffee made.

s.
ijese
Forum Members
Forum Members
Posts: 19
Joined: Sun May 14, 2006 2:36 pm

Re: Serving random page

Post by ijese »

Thanks scooper, seems exactly what I need :-)

Can I use the same technique to track outgoing clicks? If I create a different dummy page with just a redirect in it (implemented the same way like here), it would show in my website logs/statistics one should think!

Regards,
Igor
Post Reply

Return to “CMSMS Core”