Using php to split test landing pages

I wanted to post the results of something I've been working on for the benefit of the QYDJ community. Those folks reading this that have a good handle on php are probably not going to get much out of this, but those like me that are php hacks might be able to make use of some of it.
I've hacked my way through a simple method to split test ads (for conversions, and not just CTR) and landing pages simultaneously using php. It combines some of the info found on other threads in this forum and some advice from other locations on the web.
To do this I've created a php file that I'm using as the destination url for my campaigns, called split.php. The code in the file calls a parameter ("ad") from the ad destination url and then randomly assigns a link to send the user to:
<?php
switch($_REQUEST['ad'])
{
case 'ad1':
$link[0] = "http://www.mysite.com/landingpage1.php?sid=11".$_GET['sid'];
$link[1] = "http://www.mysite.com/landingpage2.php?sid=12".$_GET['sid'];
srand ((double)microtime()*1000000);
$randomnum = rand(0, count($link)-1);
header ("Location: $link[$randomnum]");
break;
case 'ad2':
$link[0] = "http://www.mysite.com/landingpage1.php?sid=21".$_GET['sid']."&page=".$_GET['page'];
$link[1] = "http://www.mysite.com/landingpage2.php?sid=22".$_GET['sid']."&page=".$_GET['page'];
srand ((double)microtime()*1000000);
$randomnum = rand(0, count($link)-1);
header ("Location: $link[$randomnum]");
break;
default:
$link[0] = "http://www.mysite.com/landingpage1.php?sid=1".$_GET['sid'];
$link[1] = "http://www.mysite.com/landingpage2.php?sid=2".$_GET['sid'];
srand ((double)microtime()*1000000);
$randomnum = rand(0, count($link)-1);
header ("Location: $link[$randomnum]");
}
exit();
?>
The code appends two numbers to the start of the SID to designate the ad and landing page that the user was presented, where the first number is the ad number and the second number is the landing page number. More cases can be added to split test more landing pages and ads.
I've been looking for a way to alternate the destination link so that I get an even number of users sent to each link, because of course random does not mean evenly distributed. However, with a big enough sample size the results should normalize to about 50% of users sent to each link.
Is anyone aware of a method to alternate the link evenly using php? Or any other method of accomplishing this?
A couple more questions: is anyone using Optimize My Site also split testing landing pages and ads? If so, how? (Jeremy?)
Also, using split.php in the destination url of the ad means that I'm not able to use keyword-level destination urls, eliminating keyword-level tracking. Does anyone know of a way to split test ads (for conversions and not just CTR) while also tracking at the keyword level? Is there a software program that does this? To this point I've been optimizing my campaigns with keywords and landing pages first and leaving ad testing until I have those elements under control, then testing ads separately.
Thanks!
Mike

Mike,
Bear with me because you're a much better hack at PHP than I am :)
After I read your post I did a quick search and ran across this article on evenly distributing a list of random numbers. What I took away from it (as best as my ADD enhanced brain can understand) was that maybe you could put your links into an array. Then you could save the array index pointer in a cookie so that each time the code was accessed you could check to see what index pointer was used last and then choose the new link based on that. Make sense?
Here's the link:
http://www.php-scripts.com/20051212/72/
Hope this helps :( ?
-Michael
You could use an auto-increment field in a MySQL database as a counter, however, my friends with experience in statistics tell me this is not a good idea. It's actually better to use the mt_rand() function in PHP.
Example:
<?php $page[0] = 'http://www.microsoft.com/'; $page[1] = 'http://www.google.com'; $page[2] = 'http://www.yahoo.com'; $version = mt_rand(0,2); header("Location:$page[$version]"); ?>It may appear that the pages don't redirect evenly, but over time each page will be displayed 33.3...% of the time.
Yes - but it involves some code tweaking. I didn't really want to market OMS as a split testing utility because that opens up a whole new can of support issues, however, it can be done. Send me an e-mail and I'll reply with a modified script.
OMS can do this... you just need to append your split script to tracking.php in OMS. It's a little difficult to explain here - without revealing the code - so e-mail me and I can show you how.
Best,
Jeremy
Code sent. Enjoy!