FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


HTML or php Rotation of Advert script needed





Possum
Hi

My page has 3 positions on it where I have Google adds. I would like to advertise my own site in these postions.

See Example


I want to insert my own code where the google adds are. But I would like to rotate about 20 different adds I create myself.

So I guess I need put a php variable in the HTML and insert HTML into my page.

But how can I rotate thru about 20 other HTML add snippets? and insert them in my page. So when the user moves thru my site they see different messages in those add positions


Thank you
Fire Boar
I wouldn't rotate if I were you - it's much easier to randomly pick one each time and achieves much the same effect in the end. But you need to give more information about, say, how you're storing your ads, the format of the HTML you want to produce, how proficient you are with PHP yourself, that sort of thing.
Possum
Quote:
I wouldn't rotate if I were you

I agree!!

My site has all the code and adsence code to follow what I mean.

http://udopage.com/lazarus/
jmlworld
One question, Possum. Are you using CMS (such as Drupal, Joomla, WordPress, etc...)? These CMSs has their own add management plugins/modules either built-in or separately free to download as add-on.

If you are using handmade custom script, use the code below:

Code:

<?php
function random_ad() {

  /*
   * Replace the "Ad n Here" to your real HTML ad code
   * List as many ads as you want   
   * One ad code per line
   *-----------------------------------------------------*/   
   
  $ads = "Ad 1 Here
  Ad 1 Here
  Ad 2 Here
  Ad 3 Here
  Ad 4 Here
  Ad 5 Here
  Ad 6 Here
  Ad 7 Here
  Ad 8 Here
  Ad 9 Here
  Ad 10 Here";

 // Split code in $ads into lines
 $ads = explode("\n", $ads);

 // Return a random line every time the page reloads
 return $ads[ mt_rand(0, count($ads) - 1) ];
}
?>

In the above code, we listed the ads under the $ads variable, then we used the explode() function to split the string inside $ads so we can use one line at a time. \n represents a new line. Finally we returned our exploded lines as random. 1 line at a time. PHP's mt_rand() function did this for us.

You can put the above code everywhere in your page. To show the ads in the desired position just paste following code where you want the ad to appear.

Code:

<?php
// Show the ads
function show_ads() {
 $show_ad = random_ad();
 echo "<div class='ad_1'>$show_ad</div>";
}
?>


You need to STYLE the ads so they will appear exactly the way you wanted. Make sure to create style for the selector div.ad_1.

Also you need to use these codes as many times as you want.

Inspired by: Hello Dolly plugin of WordPress
Possum
Quote:
One question, Possum. Are you using CMS


No I am using my own CMS that I am writing. I just think its a good idea to add this capability.

THx for your code Smile
Related topics
Free PHP/MySQL login script
Need a Contact form from HTML/PHP
how did you learn about html, php or other languages???
Form Processing Email Not Sent
PHP Script needed
my PHP code benchmark script that got some problems
Php voting script needed (URGENT)
I need a php upload script, NEEDED BADLY
Help with php and java script
affiliate tracking php script needed
VERY simple php script needed
anyone know of a good php form processer script
PHP Script Needed for 250 frih$
Wanting a PHP input security script: up to 1200frih$!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.