Hey guys
I thought I would share my URL rotator script with you ;-)
First of all you create a file called class.rotator.php with the following content:
<?php
class Rotator
{
private $urls;
private $file;
public function __construct($counter_file)
{
$this->urls = array();
$this->file = $counter_file;
}
public function add_url($url)
{
$this->urls[] = trim($url);
}
public function number()
{
return count($this->urls)-1;
}
public function get_next($num)
{
if($num+1 > $this->number())
{
return 0;
}
else
{
return $num+1;
}
}
public function run($simulate = false)
{
@$number = (int)file_get_contents($this->file);
$next_index = $this->get_next($number);
file_put_contents($this->file, $next_index);
if($simulate)
{
echo $this->urls[$next_index];
}
else
{
header("Location: ".$this->urls[$next_index]);
}
exit;
}
}
?>
<?php
require 'class.rotator.php';
$s1 = $_GET['s1'];
$s2 = $_GET['s2'];
$s3 = $_GET['s3'];
$r = new Rotator('counter.txt');
$r->add_url('http://trkur.com/trk?o=6093&p=XXXXX&s1='.trim($s1).'&s2='.trim($s2).'&s3='.trim($s3));
$r->add_url('http://trkur.com/trk?o=7152&p=XXXX&s1='.trim($s1).'&s2='.trim($s2).'&s3='.trim($s3));
$r->run();
?>