Page Rotator

nato76

Junior Member
Joined
Jan 6, 2009
Messages
152
Reaction score
18
I did a search and could not find this. I am running multiple offers and want a script that rotates what offers people are getting sent to.

For example:

I send an email to my list and they click on the link. I don't want them all going to the same offer. I want them going to different pages with different offers. Anyone have a script to accomplish this?
 
in its simplest form you can do this....

create each of your offers as you would do normally ie using html but save the files as php include files ie .inc instead of .html

name each offer like this ie 1.inc, 2.inc, 3.inc, etc

on your main page generate a random number using php

ie
Code:
<?php $incnum = rand(1, 10); ?>

then on your main page just call the file like this
Code:
<?php include("$incnum.inc"); ?>

every time someone loads the page it will pull in a different .inc file....

look here for more info on using include files:

Code:
http://www.tizag.com/phpT/include.php

havent tested the code but in theory thats probably the simplest way of doing it and should point you in the right diretion...

hth

thanks

ukescuba
 
Code:
switch(rand(1,10)){
case 1:
include("1.php");
break;
case 2:
include("1.php");
break;

etc..


}
works the same, more handwriting :) as well as you can use alternative filenames therefor as a Plus!
 
i'm using this:

PHP:
<?PHP

$file_handle = fopen("l.txt", "rb");
$line_of_text = fgets($file_handle);
$i = 0;
$mypages[$i] = $line_of_text;
$i=1;
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$mypages[$i] = $line_of_text;
$i = $i+1;

}

fclose($file_handle);
$myrandompage = $mypages[mt_rand(0, $i -1)];
?>

<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=<?php echo $myrandompage; ?>">

and 1.txt, whit offers (1 per line)
 
All this code is confusing me. Trying to find out which one would be the easiest to implement.
 
Managed to figure this out. The .inc extension was confusing me but now I'm like DUH. Thanks a lot for this.
 
Managed to figure this out. The .inc extension was confusing me but now I'm like DUH. Thanks a lot for this.

i use include a lot when building my own stuff they come in handy... remember if you position them inside a div layer you can place them anywhere on the screen with css

similar to joomla and positioning modules... this was my duh moment for understanding joomla template design

if you need help with css let me know! :)
 
Why does this work?

Code:
<?php $incnum = rand(1, 2); ?>
<?php include("$incnum.html"); ?>

But this doesn't:

Code:
<?php $incnum = rand(1, 2, 3); ?>
<?php include("$incnum.html"); ?>


Trying to rotate 3 pages. Works with 2. I don't know anything about php btw.
 
Last edited:
Here's a rotate with geo-location that I use.

rotate-geo-locate.php
Code:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">

var country = geoip_country_code();

switch (country)
{
case (country = "US"):
  window.location = "us/index.php";
break;
case (country = "CA"):
  window.location = "ca/index.php";
break;
case (country = "UK"):
  window.location = "rotator/uk/index.php";
break;
default:
  window.location = "rotator/int/index.php";
break;
}
</script>

us/index.php
Code:
<?PHP

$file_handle = fopen("us.txt", "rb");
$line_of_text = fgets($file_handle);
$i = 0;
$mypages[$i] = $line_of_text;
$i=1;
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$mypages[$i] = $line_of_text;
$i = $i+1;

}

fclose($file_handle);
$myrandompage = $mypages[mt_rand(0, $i -1)];
?>

us.txt
Code:
your US offers here 1
your US offers here 2
your US offers here 3
your US offers here 4
your US offers here 5

Rinse. Repeat with other countries.
 
Why does this work?

Code:
<?php $incnum = rand(1, 2); ?>
<?php include("$incnum.html"); ?>

But this doesn't:

Code:
<?php $incnum = rand(1, 2, 3); ?>
<?php include("$incnum.html"); ?>


Trying to rotate 3 pages. Works with 2. I don't know anything about php btw.

change rand(1, 2, 3) to rand(1, 3)

the numbers in the brackets are your limits - ie if you wanted to pick a random number beween 5 and 10 you would put rand(5,10)

hope that makes sense...
 
ukescuba thank you so much. That worked.

Repped and thanked.
 
Back
Top