...

View Full Version : Help Refreshing Ad Rotater



IndianProxy.com
01-01-2006, 04:33 PM
Hello. I have this code and basically what I want is that when it randomly selects to use ads_2.inc, I want to let ads_2.inc refresh once every 10 sec. Now I tried inserting a meta refresh tag into the ads_2.inc file but then sometimes it refreshes to a different ad which I do not want. Can anyone help?

Thanks



<?
srand ((double) microtime() * 1000000);

$randomnumber = rand(0,7);

$include0 = "ads/ads_1.inc";
$include1 = "ads/ads_2.inc";
$include2 = "ads/ads_3.inc";
$include3 = "ads/ads_2.inc";
$include4 = "ads/ads_1.inc";
$include5 = "ads/ads_2.inc";
$include6 = "ads/ads_1.inc";
$include7 = "ads/ads_2.inc";
$include8 = "ads/ads_1.inc";

if ($randomnumber== "0") {
include ("$include0");

} else if ($randomnumber== "1") {
print("$include1");

} else if ($randomnumber== "2") {
include("$include2");

} else if ($randomnumber== "3") {
include("$include3");

} else if ($randomnumber== "4") {
include("$include4");

} else if ($randomnumber== "5") {
include("$include5");

} else if ($randomnumber== "6") {
include("$include6");

} else if ($randomnumber== "7") {
include("$include7");

} else if ($randomnumber== "8") {
include("$include8");

} else {

echo ("ERROR: A random num is being generated out of range, or not at all ");
}
?>

rlemon
01-01-2006, 06:30 PM
main file


<?
if( !isset($_REQUEST['refresh']) || $_REQUEST['refresh'] == '0' ){
srand ((double) microtime() * 1000000);

$randomnumber = rand(0,7);
$include = array();
$include[0] = "ads/ads_1.inc";
$include[1] = "ads/ads_2.inc";
$include[2] = "ads/ads_3.inc";
$include[3] = "ads/ads_2.inc";
$include[4] = "ads/ads_1.inc";
$include[5] = "ads/ads_2.inc";
$include[6] = "ads/ads_1.inc";
$include[7] = "ads/ads_2.inc";
$include[8] = "ads/ads_1.inc";

if( ($randomnumber >= 0) && ($randomnumber <= 8) ){
include($include[$randomnumber]);
}
}
?>


now when you refresh the page using the meta tags just refresh the page loading it with

www.yoursite.com/yourpage.php?refresh=1

and when you want the add to rotate

www.yoursite.com/yourpage.php
or
www.yoursite.com/yourpage.php?refresh=0

IndianProxy.com
01-01-2006, 10:12 PM
Thanks but only thing is that it doesnt refresh. Could there be something wrong?

EDIT: nvm I got it.
Thanks

Element
01-01-2006, 10:57 PM
$randomnumber = mt_rand(0,7);
$include = array();
$include[0] = "ads/ads_1.inc";
$include[1] = "ads/ads_2.inc";
$include[2] = "ads/ads_3.inc";
$include[3] = "ads/ads_2.inc";
$include[4] = "ads/ads_1.inc";
$include[5] = "ads/ads_2.inc";
$include[6] = "ads/ads_1.inc";
$include[7] = "ads/ads_2.inc";
$include[8] = "ads/ads_1.inc";

if($randomnumber == 0 || $randomnumber <= count($include)) ){
include($include[$randomnumber]);
}
}

?>


That edit will give you less to edit if you take away array values, or add new ones, so you don't have to edit anything but the array.

and you might look into array_rand() (http://php.net/array_rand)

Velox Letum
01-02-2006, 12:10 AM
<?php
$include = array();
$include[] = "ads/ads_1.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_3.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_1.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_1.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_1.inc";

include($include[array_rand($include)]);

?>

Element
01-02-2006, 09:17 PM
<?php
$include = array();
$include[] = "ads/ads_1.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_3.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_1.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_1.inc";
$include[] = "ads/ads_2.inc";
$include[] = "ads/ads_1.inc";

include($include[array_rand($include)]);

?>

See, it is allot more simple with array_rand(), its also quite usefull since manipulating random array results the long way just takes up more time and may not be as fast.

Only problem with that is unless you want more code then you might take out the last array result because it doesn't look like you were using it.

rlemon
01-02-2006, 09:53 PM
you are all focusing on cleaning up the array - the problem was with the refreshing.

I suggest you use url variables.

so....




if(isset($_REQUEST['ad']) && ($_REQUEST['ad'] == 0 || $_REQUEST['ad'] < count($includes))){

include($includes[$_REQUEST['ad']]);

} else {

run the random add select code

}



then in the meta tag - when you refresh

call

myPage.php?ad=(Array key for said ad)
*without the perenthesis.

Element
01-03-2006, 12:09 AM
Yes, we were adding alternate advice for functionality, and quicker parsing.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum