[REQ] PhP script to redirect 50-50% the traffic

Hunwarrior

Senior Member
Joined
May 12, 2010
Messages
1,035
Reaction score
876
Hi guys,

Would some code minded guy share a script which would redirect my traffic
50% to link1
50% to link2

If i can set up/modify the ratios, even better!

Thanks, REP is in store.

ps: hope it is in the right section
 
There is a simple way, not absolutly accurate but it might work

PHP:
<?php
$urlone="SITE-ONE-URL-HERE";
$urltwo="SITE-TWO-URL-HERE";
$num=rand(0,100);
if($num<50) { header("Location :$urlone); die; }
else { header("Location :$urltwo"); die; }
?>

if you want to change ratio, change the "50"
50 = 50/100 -> siteone
40 = 40/100 -> siteone
...

it's random redirection, if you want perfect 50/50, you have to use a sql base or external file...
if needed, just ask
 
whatever i am doing, i have syntax error at line 3 ... :S
 
Try this one
PHP:
<?php
$urlone='http://google.com';
$urltwo='http://yahoo.com';
$num=rand(0,100);
if($num<50) { header("Location :$urlone"); die; }
else { header("Location :$urltwo"); die; }
?>

brazero
If you dont have any variables in string allways use single quote (') instead of double(") it's much faster cos PHP interpreter is not searching variable in string
 
Back
Top