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.

 

Link to comment
Share on other sites

<?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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.