Home >
General >
Affiliate Marketing Forum
How do you change this PHP script so it rotates 3 links instead of 2? (6)
01-23-2013 08:51 AM
#1
doryphoros (Member)
How do you change this PHP script so it rotates 3 links instead of 2?
Yeah...I feel kind of retarded, I can't figure this one out. Currently I'm using this to split traffic evenly between two offers, but how would I change it to split evenly between three offers?? I've tried a couple of things that made sense to me but none of them worked.
Code:
<?php
$random = rand(1, 2);
if ($random=='1') {
header('Location: http://xxxx.com');
} else {
header('Location: http://xxxx.com');
}
?>
01-23-2013 09:19 AM
#2
dario (Member)
use the switch/case instead
http://www.w3schools.com/php/php_switch.asp
http://php.net/manual/en/control-structures.switch.php
01-23-2013 10:41 AM
#3
caurmen (Administrator)
If you want to use this script, you'd modify it as follows:
You could also use a SWITCH, as Dario says.
However, I'd recommend using a different script altogether, unless you're specifically wanting random numbers, as there are issues with using pseudorandoms to rotate LPs - you won't get an even distribution between the LPs.
I generally like the "count.txt" approach to LP rotation - you use a separate file to keep track of which LP to show next, and show them in order.
There's an excellent script
over here on the Prosper 202 site for doing just that.
Hope that helps!
01-23-2013 07:29 PM
#4
zeno (Administrator)
I tend to use something more like this:
[PHP]
$redirect[0] = 'http://URL1.com';
$redirect[1] = 'http://URL2.com';
$redirect[2] = 'http://URL3.com';
$number = mt_rand(0,2);
header("Location:$redirect[$number]");
[/PHP]
01-23-2013 07:45 PM
#5
sandyone (Member)

Originally Posted by
caurmen
But, but I read that Propser202 can't be used to track more than one LP.
01-24-2013 02:24 AM
#6
ScottKevill (Member)

Originally Posted by
zeno
I tend to use something more like this:
[PHP]
$redirect[0] = 'http://URL1.com';
$redirect[1] = 'http://URL2.com';
$redirect[2] = 'http://URL3.com';
$number = mt_rand(0,2);
header("Location:$redirect[$number]");
[/PHP]
Better still, don't hard-code any values, as it makes it easier to edit without having to change in other places. (eg. commenting out a single redirect). Something like this:
[PHP]
$redirect[] = 'http://URL1.com';
$redirect[] = 'http://URL2.com';
$redirect[] = 'http://URL3.com';
$url = $redirect[mt_rand(0, count($redirect)-1)];
header("Location: $url");
[/PHP]
Home >
General >
Affiliate Marketing Forum