开发者

Simple A/B randomization script with PHP

开发者 https://www.devze.com 2023-03-10 11:09 出处:网络
I have two ad options in my theme, Adsense and \"Custom\". If the user enters code into the \"Custom\" field, it trumps whatever they have in the \"Adsense\" code field, so the theme places their cust

I have two ad options in my theme, Adsense and "Custom". If the user enters code into the "Custom" field, it trumps whatever they have in the "Adsense" code field, so the theme places their custom ad atop the content area. If they have adsense enabled, and nothing in the custom ad spot, the theme places their adse开发者_运维技巧nse code there.

I'd like to add an option to allow the user to opt to have my theme automatically rotate ads between adsense and their custom ads. The custom ads may be Ebay, Amazon, ClickBank, etc.

How would you set up a PHP script that will randomly choose between two options?

Alternately, I'd like to be able to give the user the option to choose a percentage value so that the adsense ads are rotated based on their chosen percentage.

Just looking for some suggested approaches. Thanks in advance.


<?php

   $option[0] = 'html option 1';
   $option[1] = 'html option 2';

   echo $option[rand()%count($option)];
?>


1) I think mt_rand(); it's better than rand(); (source:http://php.net/manual/en/function.mt-rand.php)

2) $option[0] = 'html option 1';
$option[1] = 'html option 1';
$option[2] = 'html option 1';
$option[3] = 'html option 2';

echo $option[rand()%count($option)];

It's not a better solution, but it works :)

0

精彩评论

暂无评论...
验证码 换一张
取 消