mardi 25 août 2015

Simple link picker based on PHP rand() not quite working

So I want to send 5% of my traffic to each of the first three links and the remaining 85% to the 4th and final (caught with "else"). My range for rand is 1,20.

From the following code, why would I only see the 3rd (~15% of time) or 4th (~85% of time) links returned when I echo clickref_url, never the 1st or 2nd link that should each be getting 5% of the traffic?

Thank you! Thank you! Thank you!

<?php
$rand = rand(1,20);
if ($rand == 1) {
  /* Link1 */
  $clickref_url = 'http://ift.tt/1Ly1qMd'.$email.'&var2=mydomain';
  $clickref_url.= '&firstname='.$firstname;
  $clickref_url.= '&lastname='.$lastname;
  $clickref_url.= '&email='.$email;
  $clickref_url.= '&zipcode='.$zip;
}
if ($rand == 2) {
  /* Link2 */
  $clickref_url = 'http://ift.tt/1LuVNeE'.$email.'&var2=mydomain';
  $clickref_url.= '&firstname='.$firstname;
  $clickref_url.= '&lastname='.$lastname;
  $clickref_url.= '&email='.$email;
  $clickref_url.= '&zipcode='.$zip;
}
if ($rand == 3) {
  /* Link3 */
  $clickref_url = 'http://ift.tt/1Ly1r2t'.$email.'&var2=mydomain';
  $clickref_url.= '&firstname='.$firstname;
  $clickref_url.= '&lastname='.$lastname;
  $clickref_url.= '&email='.$email;
  $clickref_url.= '&zipcode='.$zip;
} else {
  /* Link4 */
  $clickref_url = 'http://ift.tt/1LuVLDL'.$email.'&var2=mydomain';
  $clickref_url.= '&firstname='.$firstname;
  $clickref_url.= '&lastname='.$lastname;
  $clickref_url.= '&email='.$email;
  $clickref_url.= '&zipcode='.$zip;
}
?> 




Aucun commentaire:

Enregistrer un commentaire