Jump to content

Random Redirect Script in PHP - Needs modifying!! plz help :(


luke777

Recommended Posts

Hi :) right ok... this is the script i am using at the moment

 

<?php

$url[0] = "http://www.siteone.com";

$url[1] = "http://www.sitetwo.com";

$url[2] = "http://www.sitethree.com";

$url[3] = "http://www.sitefour.net";

$url[4] = "http://www.sitefive.com";

$url[5] = "http://www.sitesix.com";

 

srand ((double)microtime()*1000000);

$randomnum = rand(0, count($url)-1);

 

header ("Location: $url[$randomnum]");

?>

 

It works great but what i really need is a script so that i can control where the hits are going.

 

What i need is a script that has the option to speficy the percentage of hits thats should go to each site out of the total traffic.

 

For example:

 

http://www.siteone.com - takes 40%

http://www.sitetwo.com - takes 30%

http://www.sitethree.com - takes 10%

http://www.sitefour.com - takes 10%

http://www.sitefive.com - takes 5%

http://www.sitesix.com - takes 5%

 

I hope I have explained clearly enough what i am looking for, if anyone thinks they could help me i would REALLY appreciate it!!  ;D

 

Thanks Luke.

 

<?php
$url[0] = "http://www.siteone.com";
$url[1] = "http://www.sitetwo.com";
$url[2] = "http://www.sitethree.com";
$url[3] = "http://www.sitefour.net";
$url[4] = "http://www.sitefive.com";
$url[5] = "http://www.sitesix.com";

$l=array(0,1,2,3,4,5,0,1,2,3,0,1,0,1,0,1,0,1,0,0);

srand ((double)microtime()*1000000);
$randomnum = rand(0, count($l)-1);

header ("Location: $url[$l[$randomnum]]");
?>

I believe that should work!

I guess this would work but its still "Random"

 

Which means.... yea, its more likely to select a number that occurs more times in the list but its not as reliable as i need it to be. Do you know what i mean?

 

I need a guaranteed

 

10% on the dot (or as close as possible to).... if 10% is the case for one of the sites.

 

Mabe some kind of link "weight" setting for work.... i dont know

 

Anyone that could come up with this would be a life saver!

you'd need a static reference (file, mysql), or is this on a per person basis, cos then you could use a session variable???

 

Somthing that works with php and mysql would be good it.... (im not a coder in php but this is what the script would have to do)

 

If .... *site1count variable*

is = 30 hits

then

redirect to a different url

else

send hit to site1 url

etc

etc

etc

 

This way i could set an exact number of hits for each site!

 

Im sure someone here could come up with something like that for me....

 

Anyone that will is a star!!!!!! would REALLY appreciate it  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.