aaaaaa123456789 icon

Random link hopper

aaaaaa123456789 | PRO | 06/13/12 05:20:01 AM UTC | 0 ⭐ | 643 👁️ | Never ⏰ | []
PHP |

1.37 KB

|

None

|

0 👍

/

0 👎

<?php
 
function add_element($list, $frequency, $URL) {
  $freq = (int) $frequency;
  if ($freq <= 0) return $list;
  $list[($list['count'] ++)] = array(
    'freq' => $freq,
    'URL' => $URL
  );
  $list['sum'] += $freq;
  return $list;
}
 
function draw_random($list) {
  $randomnumber = mt_rand(0, $list['sum'] - 1);
  for ($pos = 0; ; $pos ++)
    if ($randomnumber < $list[$pos]['freq'])
      return $list[$pos]['URL'];
    else
      $randomnumber -= $list[$pos]['freq'];
}
 
$elements = array('count' => 0, 'sum' => 0);
 
/*
ADD ELEMENTS HERE
Just copy the line and modify the last two values.
The number is the frequency, the third thing is the site.
So, these lines
$elements = add_element($elements, 1, 'http://google.com');
$elements = add_element($elements, 4, 'http://jiggmin.com');
 
would add google.com with a frequency of 1 (out of the total, which is 1 + 4 = 5)
and jiggmin.com with a frequency of 4.
 
If you're unsure about the frequency, just put 1 for every site.
*/
 
$elements = add_element($elements, 1, 'http://google.com');
$elements = add_element($elements, 4, 'http://jiggmin.com');
 
 
 
if ($elements['sum'] == 0) die ('No links');
$finallink = draw_random($elements);
 
$result = <<<HTMLcode_end
<html>
  <head>
    <meta http-equiv="Refresh" content="0; URL=$finallink">
  </head>
</html>
HTMLcode_end;
 
echo $result;
 
?>

Comments