Ad Rotate Help

Started on the old forum in April 2013 · view the original in the archive · old links redirect here

12 replies · 807 views · started 13 years ago · 1 min read

4 participants
brentg Developer · 95 posts #1

Hi, how can make this script allow me to use php include so i can randomize my ads.

When use php include i get an error.

<?php
$quot_arr = array(
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
$quot_rand = array_rand($quot_arr);
echo '<center><b>AD:  </b>';
echo ' '.$quot_arr[$quot_rand].'</left>';
?>
   

or if there is a better ad rotate script without sql so that i can use with buzzcity,adiquity,reporo etc etc

Thanks

Free Mobile Downloads: http://playwap.mobi

metulj Super moderator Principal · 1,726 posts #2

brentg wrote: Hi, how can make this script allow me to use php include so i can randomize my ads. When use php include i get an error.

<?php
$quot_arr = array(
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
'<a href="http://example.com">Example</a>',);
$quot_rand = array_rand($quot_arr);
echo '<center><b>AD:  </b>';
echo ' '.$quot_arr[$quot_rand].'</left>';
?>

or if there is a better ad rotate script without sql so that i can use with buzzcity,adiquity,reporo etc etc Thanks

This was posted here already, i just can't find the topic, no SQL needed. In randAd.php

<?
$randDat = @file("adData.dat");
$random_num = rand (0,count($randDat)-1);
$udata = explode("::",$randDat[$random_num]);
echo $udata[1];
?>

and in adData.dat

::ad link 1
::ad link 2
::ad link 3
::etc

It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt. ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ ! ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.

キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

brentg Developer · 95 posts #3

So will i just include "randad.php" in all my pages

and put all the codes in "adData.dat"

like so:

:: paste buzzcity full code here
:: paste reporo full code here
::etc..

Thanks

Added after 22 minutes:

ok tested it. working perfectly with:

<script> example <script>

not working with: (Reporo)

<? echo getAdMarkUP($adArraySPC['xxxx']); ?>
<?php include("example"); ?>

and Buzzcity ad codes

Free Mobile Downloads: http://playwap.mobi

GumSlone Administrator Principal · 1,690 posts #4
<?php 
$rand = rand(0,100);
if($rand >=66)
{
//include somthing else
//echo something else
}
elseif($rand >=33)
{
//include reporo
//echo reporo
}
else
{
//include buzzcity
//echo buzzcity
}
?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

brentg Developer · 95 posts #5

Thanks Gumslone. Could you please share how I will integrate that into my site

Free Mobile Downloads: http://playwap.mobi

brentg Developer · 95 posts #6

Manged to figure it out.

 <?php 
$rand = rand(0,100);
if($rand >=66)
{
include('/ad1.php'); 
}
elseif($rand >=33)
{
include('/ad2.php'); 
}
else
{
include('/ad3.php'); 
}
?> 

GumSlone can you perhaps say how this code work, i see its using random number. What does this line mean if($rand >=66) and what will happen if i change it

Free Mobile Downloads: http://playwap.mobi

GumSlone Administrator Principal · 1,690 posts #7

its percentage,

first line you set random values from 0 to 100, if you want to show 3 different ads in random order divide 100/3 = 33.3333.. so in average from 100 page requests the ad1 will be shown 33 times, same for ad2 and ad3.

if you want to set priority ie for ad1 50% and for ad2 and ad3 remaining 50% in equal manner you have to do like this:

<?php  
$rand = rand(0,100); 
if($rand >=50) 
{ 
include('/ad1.php');  
} 
elseif($rand >=25) 
{ 
include('/ad2.php');  
} 
else 
{ 
include('/ad3.php');  
} 
?>

if you want to show 4 different ads divide 100 by 4 will be 25, so the code will look like this:

<?php  
$rand = rand(0,100); 
if($rand >=75) 
{ 
include('/ad1.php');  
} 
elseif($rand >=50) 
{ 
include('/ad2.php');  
} 
elseif($rand >=25) 
{ 
include('/ad3.php');  
}
else 
{ 
include('/ad4.php');  
} 
?>

actually to be more correct the rand value should start with 1 ie. $rand = rand(1,100); but it doesn't change much if you start with 0.

PS. according to php.net mt_rand it even better than the rand function, but rand is well known and most used, so its up to you which function to use.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

brentg Developer · 95 posts #8

Awesome, understand now. Thanks so much

PS when yo say 100 by 4 = 25% howcome your percentage in the example below is not 25% each, mistake?

 <?php  
$rand = rand(0,100); 
if($rand >=75) 
{ 
include('/ad1.php');  
} 
elseif($rand >=50) 
{ 
include('/ad2.php');  
} 
elseif($rand >=25) 
{ 
include('/ad3.php');  
}
else 
{ 
include('/ad4.php');  
} 
?> 

Must all your percentages add up to 100% or is each $rand>= separate to the other for example one can 70 and the other 50??

Free Mobile Downloads: http://playwap.mobi

GumSlone Administrator Principal · 1,690 posts #9
<?php   
$rand = rand(0,100);  //gives random number between 0 and 100, including 0 and 100
if($rand >=75)  
{  
// if the random number is larger or equal 75 show the first ad, this is 25%
}  
elseif($rand >=50)  
{  
//if number is larger or equal 50 but lover than 75, show the second ad, this is 25%
}  
elseif($rand >=25)  
{  
//if number is larger or equal 25 but lover than 50, show the third ad, this is 25%  
} 
else  
{  
//if number is lover than 25, show the ad number 4, this is 25%
}  
?>

you could do it also like this:

<?php    
$rand = rand(0,100);  //gives random number between 0 and 100, including 0 and 100 
if($rand <= 25)   
{   
// if the random number is lower than 25 show the first ad, this is 25% 
}   
elseif($rand <= 50)   
{   
//if number is lower or equal 50 but larger than 25, show the second ad, this is 25% 
}   
elseif($rand <= 75)   
{   
//if number is lower or equal 75 but larger than 50, show the third ad, this is 25%   
}  
else   
{   
//if number is larger than 75, show the ad number 4, this is 25% 
}   
?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

brentg Developer · 95 posts #10

That makes much more sense now. THANKS!!!

Just to make sure:

 <?php 
$rand = rand(0,100);
if($rand >=45)  [B]/////// 55%[/B]
{
include('ad2.php'); 
}
elseif($rand >=20) [B]///////// 25%[/B]
{
include('ad3.php'); 
}
else                  [B]////////////// 20 %[/B]
{
include('ad4.php');  
}
?> 

Free Mobile Downloads: http://playwap.mobi

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close