AJAX banner rotation

February 13th, 2006. Tagged: Ajax

So here's the case: rotate ads on a website, even when the page is not reloaded. If the chances are that the visitor will spend more time on a page, it makes sense to opt-in for displaying more than one ad at one page load. I've done this in the past using iframes, but hey, it's 21st century (the last time I checked) and we have AJAX! ;)

I also wanted to have the flexibility to display any ad type, which means I should be able to rotate pieces of HTML, rather than just images. Using HTML chunks, the ad can be an image, or formatted text, or swf, etc.


If you're curious to see the demo, go straight ahead (nothing impressive, I must admit, just rotating stuff ;) ).

Getting busy

The "architecture" is fairly trivial - one HTML page (demo.html) and one JavaScript (ajax-banner.js) that makes XMLHTTP requests to a server-side script (ajax-banner.php). The server side (that has all the logic to figure out the next advertisement to show) returns XML response which is received by the caller JS and then displayed in a div on the HTML page.

<div id="ajax-banner"></div>

The server-side script

For the purposes of the example, the ad logic is simple - an array of HTML chunks, we pick a random one and return it as part of the XML response. In addition to the HTML chunk, as part of the XML response, the server-side script also produces an "instruction" as to how long should the ad be displayed.

Here's how the script looks like:

// an array of banners
$banners = array (
    '<em>ban</em>ner 1',
    'banner <strong>2.0.</strong>',
    '<h1>big banner</h1>',
    'Inline JS won\'t run :(  <script>alert("boom!")</script>',
    'External JS won\'t run :( ( <script src="test.js"></script>',
    '<img src="phpied.gif" />'

// pick a random one
$html = $banners[array_rand($banners)];

// send XML headers
header('Content-type: text/xml');
echo '<?xml version="1.0" ?>';

// print the XML response
    <content><?php echo htmlentities($html); ?></content>

The javascript

The javascript consists of three functions. The main "dispatcher" is nextAd() which loads the next ad in the div. nextAd() calls the makeHttpRequest() function to send a request to the server-side script and then passes the response to loadBanner() which actually updates the banner div.


I've been using this simple function I came up with for a few projects (like theInvisibleAd.com) No AJAX libraries or toolkits are necessary as the task is pretty straightforward.

This function makes an HTTP request and passes the response to another function, specified on-the-fly. The function is the bare basics of the AJAX thing and if you're interested in the details you can check my article on SitePoint where I've used it to create a simple web console application.


This function makes the request and passes the response to loadBanner(). The HTTP request uses the current time in milliseconds to try to prevent the client browser from using a cached copy from the previous request.

function nextAd()
    var now = new Date();
    var url = 'ajax-banner.php?ts=' + now.getTime();
    makeHttpRequest(url, 'loadBanner', true);


loadBanner() accepts the XML response generated by the server-side script. The XML has two tags - content (the HTML to be displayed) and reload (the allocated time for this ad to be displayed). The banner div is updated with the new HTML content using innerHTML the simplest, yet questionable by some purists, including myself, way of updating an already loaded page with JS.

Once the ad is updated, old timeout is cleared (if any) and a new timeout is set, the time in milliseconds after which we'll call nextAd() again to make the next HTTP request.

function loadBanner(xml)
    var html_content = xml.getElementsByTagName('content').item(0).firstChild.nodeValue;
    var reload_after = xml.getElementsByTagName('reload').item(0).firstChild.nodeValue;
    document.getElementById('ajax-banner').innerHTML = html_content;

    try {
    } catch (e) {}

    to = setTimeout("nextAd()", parseInt(reload_after));


There's one drawback to this method though - any javascripts (inline or external) in the ad's body won't get executed. I have a remedy for this - including JavaScripts on the fly, outlined in this posting, but in this case I need to know something about the HTML returned by the server-side script, which can be passed as another tag in the XML, saying something like <is-this-js> -> you bettcha! In this case the solution will become less of a one-size-fits-all, but still a viable option.

Overall, if you don't plan to use JS in your ads, the solution outlined in this post is very simple and seems like ideal for replacing iframe-based banner rotations using sexier AJAX.

Tell your friends about this post: Facebook, Twitter, Google+

144 Responses

  1. [...]
    Ajax13 Feb 2006 03:50 pm
    AJAX banner rotation

    Check this cool script “AJAX banner rotation” , Sort of Ajax version of phpadsnew but th [...]

  2. Good stuff, thanks for sharing!

  3. test

  4. Saved me a lot of work. thnx!

  5. Nice. I prefer this one over php rotating banners.

  6. Demo page don’t work.

  7. [...] AJAX Banner RotationRote las publicidades de un website, incluso cuando la página no se recarga. [...]

  8. [...] AJAX Banner RotationRote las publicidades de un website, incluso cuando la página no se recarga. [...]

  9. Appriciate the script, however it seems to be a problem running to diffrent banners at the same page?

  10. This is great!

    Now, can it be made to work with some sort of transition effect?

  11. I can’t seem to get the demo working. I would also be interested in this with some transition effects. I have been trying to use this with the script.aculo.us effects like this site has done.

  12. Thanks for all the comments, I’ll try to do some more work on the script, although it was meant more as a proof of concept, not so much as a production-ready plug’n'play thingie.

    Evandro, David, I just checked the demo and seems to run OK. YOu don’t say it’s not working because it says “Inline JS won’t work”, it’s just a text.

  13. This is great, anyone know of one that works with ASP pages (the rest of the page it needs to sit on is ASP)

  14. great resource…thanks

  15. Cool tip … i need to implement something similar myself for my blog ;)

  16. [...] The “architecture” is fairly trivial – one HTML page (demo.html) and one JavaScript (ajax-banner.js) that makes XMLHTTP requests to a server-side script (ajax-banner.php). The server side (that has all the logic to figure out the next advertisement to show) returns XML response which is received by the caller JS and then displayed in a div on the HTML page. [...]

  17. The demo does not work in firefox. Aparently your script is coded to only work with the IE xml requests methods but not the mozilla ones.

  18. Hey Billy, thanks for the feedback!
    Just tested again with FF and it worked. Which verison are you using?

  19. Ok here’s a noob question:

    How can I make it so it’s not random and goes in order?

  20. Hi csm240,

    You can keep a session variable with the index of the banners array and then increment it every time.

    So just replace
    $html = $banners[array_rand($banners)];
    with something like (not tested, so there might be a spelling error somewhere)

    if (
        !isset($_SESSION['banner_index']) // not yet set
        ($_SESSION['banner_index'] == count($banners) - 1) // already at the end
       ) {
        $_SESSION['banner_index'] = 0; // start from the beginning
    } else {
        $_SESSION['banner_index']++; // increment to the next 
    $html = $banners[$_SESSION['banner_index']];
  21. The demo and JS link does not work anymore.

  22. Little Frog, maybe it was a temporary thing. Just tried now and the links worked. The demo even worked in the ancient IE5.5. ;)

  23. Demo wasn’t working for me either, until I realized I had adblock on. Once I whitelisted the page, it worked fine.

    Awesome tool!

  24. [...] Ajax Banner Rotation : PHPied [...]

  25. Great tutorial. I’ve just ben using it in a site I’m currntly building, however, when I decided to store the banner images as BLOBs in a database IE produces some rather annoying flicker affect like its talking to the database each time it manages to load the image though my getImg.php script which just returns the blob as a jpg.

    Anyone else had this problem?

  26. Thank you for this wonderful script!

    I just worte a little script to get banners from a database.

    Connect to the databse as usual.

    $query = ”
    $result = mysql_query($query) OR die(mysql_error());

    while ($row = mysql_fetch_array($result, MYSQL_NUM))
    $banners[] = “”;

    Just in case, somebody needs this.

    And yeah. IE seems to kind of reload.

  27. [...] Ajax Banner Rotation : PHPied [...]

  28. [...] Ajax Banner Rotation : PHPied [...]

  29. [...] Ajax Banner Rotation : PHPied [...]

  30. AJAX Banner Rotation – no page refreshing needed by user…

  31. [...] Ajax Banner Rotation : PHPied [...]

  32. may i know the demo.html script?

    i try to test the demo.html but failed

  33. [...] AJAX Banner Rotation Rotate ads on a website, even when the page is not reloaded. Share this page: Written by mbballard on November 20th, 2006 with no comments. Read more articles on AJAX. [...]

  34. hi

    is it possible to configure the script, that it displays the banners in order and with every reload with a different picture at the beginning… arrays like

    Banner 1 Banner 2 Banner 3 … 45678
    Banner 2 Banner 5… 874136


    i have no idea how to change it

  35. Dont know if im doing something wrong or what, but when I use the script, it tends to show the style, but doesnt show anything from the $banners = array… any suggestions?

  36. I kinda take last post back, I put it in my webpage, and now i get a popup warning that says “There was a problem with the request. (Code:404)

  37. Hi Tim,

    Looks like there might be something wrong with the path to your ajax-banner.php. Try putting it in the same directory as the html that calls it. 404 code is for Page Not Found.

    Let me know how it goes, if you want, give me a link to the page where you tried it.


  38. ok,, sorry took so long to post,,, wife goes to college, my 3 kids go to school, and I am the unemployed bum doing alot of things for his mum…lol.. thanks stoyan…

  39. Ok, huge question, was going to upload it to my main server, dont know if works there yet,, but cant use this in a php like ban.php file, correct? has to be html? cuz, I was putting it in a file for my test page to view the banner ban.html, and pulling the information into it, saving it as ban.php… changed it to ban.htm and it works fine,,,

  40. and this wasnt exactly made for running more than one banner on the exact same page, correct? I love ajax, and this has turned me into wanting to learn more, but think I need something for my site that has alot more poof…lol…. what Id like to have, ive found, but unfortunatley it doesnt let you use more than one banner on the same page either…
    all I wanted was a script,,, I work with php mostly… that took information for a banner,,, and put that banner in a rotation in a specific stop… say 728×90 in the top middle… then haveing 2 other smaller banners right next to it on both sides… say 120×90 on the top left, and top right… and have all these banners change with javascript or ajax,,, within so many seconds, not when the page refreshed… and it let me set a month to month date so when the banner is paid for by month, I can say, paid for 3 months… and it would stop that banner on that month,, and Id have to update it when the client paid… this is why im trying to learn more about this… found this exact script in javascript and php at http://www.allgigs.co.uk/Developers/index.php, but i was going to work on an administration script for it, and maybe be able to add company name, and such to the database, wich was only a text database… this is what the owner of the script sent me about it in an email…

    I’m afraid it will take quite a bit of work to make it able to display more than one advert. It was only ever designed for one, so is pretty-much hard-coded that way.

    As a hint: the problems are with the fact that we retrieve the DOM elements for the IMG and LINK by the fixed names “ADLINK” and “AD” – you’d need the ability to rename these – adding a number etc. Next problem will be setting the “timeout” so that they are updated according to the frequency. Last problem: you probably don’t want the same ad displayed multiple times, so will need to cater for this.

  41. darn, sorry so long,,, but would like to see an ajax version just like this with php,, but try to get it to work with multiple ads per one page, and different sizes…. with php of course,, I just dont know enough about ajax, or even javascript for that matter…

  42. Hi Tim, the thing is that I created this pretty much as a proof of concept, not so much of a plug/play type of script. I’ll try to find some time to take it to the next level, but I cannot give you any time estimates :(

    For the html/php question, I don’t see a reason why the page that contains the banners should be HTML and not PHP, should work either way.

  43. lol…yea, i didnt really mean it like that,, just been trying to find ways for me to learn more myself to get to the point where you guru’s have… i never got into javascript, and was hesitant on ajax,,, but then the more and more i see things that i like,,, ive been wanting to learn more,, ive been working with php for 5 years,,, and never learned how to work with flash, javascript, ajax, or other scripting languages to work along side of my php… I did get the script to work on php by the way,, and it was a path problem… I liked the script I mentioned above because I thought it was something I could work with, without having to learn javascript… but see,,,, I also learned a valuable lesson,,, If you want something,, in particular,,, your best bet is to make it yourself… then if others like it also, make it available to them,,, same thing you have done with this script,, It gives me a better understanding,,, but for someone with my mentality of working with php so long,, I try to code everything with php… kinda need a step by step… so, starting to learn some javascript for beginners now… and thats because of you,,, I like what you did,,, so,,,, time for me to learn more to… where I come from you have to move to a big city to make any money at this,,, and with no certifications, hard to get here, unless again,, big city,,,lol… you make the script the way you make things,, not for the way others would like you to make it,,, this was a tutorial to show others,,, heck,, let them make it the way they want,,, dont let me push you into something,,,lol… but,,,is nice to have someone to talk to that knows something of what your talking about,,, my wife,,, the nurse… “honey, I have no idea what php is,, what javascript is,,, can you find someone else to talk to about it,, i dont mind listening, but have no idea what the heck your saying and maybe you should be in a mental ward..” same way i feel about her nursing….lol.. thanks,,, its mostly nice to have people you can talk to that have an understanding of what your doing… I will try to work with this script, and like the idea of ajax,, but have to start with javascript first or will never understand what certain things do… and have to do it on my own… course,, if you do update this,,, ill be back to check here and there,, but still have to make my own to know what im doing… from scratch,,, doing that now in php, but learning javascript to help with that script,, learning what I need to know,, and other ideas out there…

  44. Hey Tim, thanks for your nice comments. I’m also explaining things to my wife, and she seems to listen very hard, probably thinking of other things at the same time, heh :)

    BTW, there is this HTML_AJAX package from PEAR, you might want to take a look at it, as it aims to take care of the JS part for you. You do your PHP, it shoudl do the rest. In case you want to postpone diving into javascript yet. Although it’s a lot of fun, it really is.

  45. Forgot the URL: http://pear.php.net/package/HTML_AJAX/

  46. thanks stoyan, ill try that html_ajax out.. see where it gets me… currently Ive developed a script for banners that has date-start,duration,company-name,company-email,company-phone,to-url,to-banner,alt,target in a text file,,, this way I can start, stop by month, and so far that works,,, wont show banner past set duration which is so many months, and all other info I think I would need for a client, it shows the banners, and I can deal with the monthly, just getting ready to work on the rotation of banners now,,, I want them to change every so many seconds,,, but think I might have to start out with the basic page refresh for now, till i get things straight for javascript and/or ajax…

  47. Just shows the banners right now, one on top of other,,, basic output from an echo right now…
    echo ‘‘;

  48. Exelent script for ads, thaks you from france!

  49. Thanks you, I will add this on my web site :) Very good

  50. I am not good at maths, and this protection you have got me floored. Thanks for the great script.

  51. Ananth, heh, yes, the math can be hard sometimes. But that’s life – full of comment spammers and I need some sort of protection, otherwise I was getting like 1000 spam comments a day. Yak!

  52. Just to say, great resource..a very nice image script….I have linked to your page on my ajax resource site http://www.ajaxshack.com Hope that ok…. :-)

  53. Nice script. instead of using it as a an ad rotator, I altered ajax-banner.php to have it load a dynamic chat page every 2 seconds which updates a chat page without flicker.
    // print the XML response


    However, I have run into a strange problem. The chat page will only load 14 lines and no more. No matter how much text is on the line, the chat page will load 14 lines of chat output and then it stops. A control page shows that new additions to the chat are being added just fine, but the ajax-scripts will not display more than the 14 lines, regardless of how many extra lines of chat are added. I have verified that this is not a limitation of PHPs “file_get_contents” function. Is there some limitation in the .js file somewhere or some inhernet limitation with the technology it uses that limits the ultimate size of the file that it calls? Thanks for helping with this perplexing situation.

  54. I have found that the above mentioned issue resides in FireFox but does not reside in IE 7. Thus, Firefox, for some reason, will allow the display through the Javascript of only approx 14 lights of output and then fails to display further content from the include page.

  55. Hi Bill, this sounds strange. Do you have a test page somewhere, I’d like to see it.

  56. [...] Ajax Banner Rotation : PHPied [...]

  57. Hello..

    I tried to run and its working… but i need help if i want to get banner from database its not working…

    JS gives an errror like… Object Is Expected can anyone tell me the Solution

  58. I have problem to using this script at more than one time on same page?

    Means if the banner display top side as well as right side

    It cannot works,

    Give me any suggest

  59. errors everywhere, headers already sent, and also echoes the php source lol

  60. headers already sent and echoing the php

  61. there was a problem with the request (CODE: 404)

    why the above error?

  62. nice, but why can’t I get it to rotate, surely this is why it’s AJAX powered?
    Any reply gratefully recieved

  63. Anyone come up with a solution to the firefox problem?
    An example can be found here: http://www.christopher-allen.co.uk

  64. Thanks, Its almost like the Ajax-S slideshow, I mean the concept :)

  65. Here is an ASP version of the script:

    banner 1″,”banner 2.0.“,”big banner”,”Inline JS won’t run :( alert(‘boom!’)”,”External JS won’t run :( “,”")

    ‘Pick a random one
    Randomize Timer
    lrandom = Int(Rnd * (UBound(banners) + 1))



  66. Here is an ASP version of the script:

    <%@LANGUAGE="VBSCRIPT"%><%response.ContentType="text/xml"%><?xml version="1.0" ?>
    banners = Array("<em>ban</em>ner 1","banner <strong>2.0.</strong>","<h1>big banner</h1>","Inline JS won’t run :( <script>alert(‘boom!’)</script>","External JS won’t run :( <script src=’test.js’></script>","<img src=’phpied.gif’ />")

    ‘Pick a random one
    Randomize Timer
    lrandom = Int(Rnd * (UBound(banners) + 1))


  67. Make your own Ajax loading indicators with http://www.webscriptlab.com

  68. [...] Ajax Banner Rotation : PHPied [...]

  69. Is there no way to include an External or Inline JS source? or does this take more coding, let me know if it can be done in some way, thanks and great work.

  70. [...] Ajax Banner Rotation : PHPied [...]

  71. [...] Ajax Banner Rotation : PHPied    [...]

  72. nice , but there is a problem to using at more than one time on same page
    is there no way to include an external java script source??

  73. I’ve just been using it in a site but there was a problem with the request (CODE: 404) why the above error?

  74. I’ve created a back end in coldfusion if anyone is interested: http://www.succor.co.uk/index.cfm/2007/7/28/Banner-rotation-via-Ajax

    Thanks for the code, great work.

  75. >I’ve just been using it in a site but there was a problem with the request >(CODE: 404) why the above error?

    Could you paste your code? we will analyze it.


  76. Can some help me how can i make fade effect

  77. [...] Imran, have a quick look at this. This came out as first for the "ajax banner rotator" keyphrase __________________ dmx rgb laser projector Link Bid download free shopping cart script [...]

  78. PsYhlO which problem do you have? For me the Code is working great

  79. How can this be adapted to be used with MOSS 2007 to rotate the default top site image?

    Looks great, thanks in advance!

  80. [...] AJAX Banner Rotation AJAX banner rotation. Rotated banner ads and even chunks of HTML. [...]

  81. I need this script to rotate value click ads every minute because a user might play a game for 5 min and see the one ad. Can this be done? I will be willing to pay for help.


  82. Nice script, bit insecure and unreliable, like all ajax aps.

  83. hi is it possiable to get 2 or more adds out at once from it?

  84. Hello
    all i think best ad Rotator is Simple Ad Rotator

    link : http://www.phpbuddy.com/article.php?id=4

    you can add banner + add Ad and more ….. and can edit fast your banner and ads for All page


  85. for show file php in html you can use tag downl

  86. [code]


  87. [...] AJAX Banner Rotation AJAX banner rotation. Rotated banner ads and even chunks of HTML. [...]

  88. [...] Ajax Banner Rotation : PHPied [...]

  89. I am not good at maths, and this protection you have got me floored. Thanks for the great script.

  90. thanks

  91. Thank you..

  92. Hello
    how i can user an javascript ads like openads code?

  93. can i use adsense code with this script rotation?

  94. How can I make it so it’s not random and goes in order using ASP? Love the Banner code

  95. Using ASP how can i make the banners appear in order instead of randomly? Love the Banner code

  96. I just get an alert “There was a problem with the request (code 404). I copied the demo + js as is & still get the problem, in FireXox + IE.

  97. [...] AJAX Banner Rotation AJAX banner rotation. Rotated banner ads and even chunks of HTML. [...]

  98. [...] AJAX Banner Rotation AJAX banner rotation. Rotated banner ads and even chunks of HTML. [...]

  99. Great and excellent article it’s realy helpful. Thanks again.

  100. Very useful and exactly what I needed.

  101. Great Post, and thanks for sharing it was exactly what i was looking for. keep up the good job :)

  102. ya rite but some times its not work yaar. Give me some more info

  103. hi..how to make it random from certain folder?

  104. Nice script. is it possible make text to fade out?

  105. Nice script. is it possible make text to fade out?

  106. [...] AJAX banner rotation [...]

  107. [...] Banner Rotativo en AJAX Si ese es el caso: rotar los anuncios en un sitio web, incluso cuando la pgina no se recarga. Si hay posibilidades de que el visitante va a pasar ms tiempo en una pgina, tiene sentido optimizar para mostrar ms de un anuncio en una pgina de carga. VER EJEMPLO http://www.phpied.com [...]

  108. [...] AJAX Banner RotationAJAX banner rotation. Rotated banner ads and even chunks of HTML. [...]

  109. Hi can anyone help me.

    Can’t run php, has to be asp. used the following asp. But get a Code 500 error

    banners = Array(“banner 1″,”banner 2.0.“,”big banner”,”Inline JS won’t run alert(’boom!’)”,”External JS won’t run “,”")

    ‘Pick a random one
    Randomize Timer
    lrandom = Int(Rnd * (UBound(banners) + 1))



  110. Hi can anyone help me.

    Can’t run php, has to be asp. Changed the php to asp. But get a Code 500 error

  111. You have very interesting site.Thanks for all.

  112. I’m thinking will it be an impact for those with javascript disabled.
    Overall, it’s a nice and handy script for most of the webmaster.
    But my tracking system telling me that close to 24% of my visitor have their javascript disabled.


  113. I also have problems with the fade effect :(

  114. I like that script too!
    That was exactly that what i was looking for! Thanx

  115. the script dont work for me , i have this error message :
    There was a problem with the request. (Code:0)
    Thanks for your help !

  116. its been asked multiple times already, but has anyone come up with a solution for displaying multiple instances on one page?

  117. Does anyone have an old cgi script called: Banners Pro v2.5? It is a free script but the publishers site is no longer online and I can’t find the script anywhere. I was just hoping that maybe someone has this script somewhere on the pc with other banner rotation scripts. It’s a cgi script btw. Here’s a view of the admin area login page from a site that I found, but I can’t seem to get the files from that site:


  118. Hi, love this script and have used it before on a PHP server but want to use it on ASP server now. I’m not an ASP developer though and have been struggling with the implementation.

    I have used the ASP code that has been posted above, and modified the JS to point to the ASP page but I just get an Error 500 (http status, “Internal Server Error”).

    Could anyone help me out with this? I’d really appreciate it :)

  119. I need to put 2 or 3 banners rotating in 4 different places of my website. This code only works for 1 of them, rotating 3 banners in one place, but the others are not being shown. Any sugestion? Thanks a lot!

  120. A very nice peice of code, but have you considered using JQuery to add a fade in/out effect. Something like http://spaceforaname.com/galleryview-default.

    I think it would add alot more impact if using it for something like advertising or other things along those lines!

  121. [...] AJAX Banner Rotation Rotate ads on a website, even when the page is not reloaded. SPECIAL NOTE:The source code for aPop and footoo have now been released. Please see my post here. [...]

  122. to get off a little error just need to declare the variable to in the try function like this
    try {
    var to;
    } catch (e) {}

  123. var html_content = xml.getElementsByTagName(‘content’).item(0).firstChild.nodeValue;

    i got the error ‘object required’ at the above line.

    Please help


  124. On Both IE and Firefox I randomly get this error. “There was a problem with the request.(Code: 0)” It usually occurs when I click a link (not necessarily a banner in the rotation) anywhere. Right before the page unloads and loads into the linked page I will get that error message. Only problem is, its random at best and will not happen every time. Just now and again here and there, however noticeable. I get a fair amount of traffic on the site I am using this on so I don’t want the people coming to the site assuming that somethings wrong and attempt to leave.

    Any Ideas as to what is causing the error mentioned, and any ideas as to how I can catch them and prevent them?

  125. is there a way out that I can display two different banner set on the same page?

    ie. I define two different array of banners and I use two different divs which display one banner from the respective array?

  126. Hy all!

    I made some modification to the script, so that to work with anchors on the images…it reads the files from a folder u specify, then reads the names of images and links to them from a text file…modifications were made only in the ajax_banner.php file, so i’m posting just that!:) hope this helps anyone…Good day all

    “, $banner);
    $banner_img = $folder.$banner_parts[0];
    $banner_link = $banner_parts[1];

    $banner_just_img = ”;
    $banner_with_link = ‘‘ . $banner_just_img . ‘‘;
    $banner_html[] = $banner_with_link;

    $banner_html[] = ”;

    // pick a random one
    $html = $banner_html[array_rand($banner_html)];

    // send XML headers
    header(‘Content-type: text/xml’);
    echo ”;

    // print the XML response


  127. my bad…
    complete code follows:

    $folder = ‘images/’;
    $settings['img_ext'] = array(‘.jpg’,’.gif’,’.png’,’.swf’);
    if (substr($folder,-1) != ‘/’) { $folder.=’/'; }
    $flist = array();
    foreach($settings['img_ext'] as $ext)
    $tmp = glob($folder.’*’.$ext);
    if (is_array($tmp))
    $flist = array_merge($flist,$tmp);
    $banner_html = array();
    if (count($flist))
    $filename = $folder.”links.txt”;
    $banners = file($filename);

    foreach ( $banners as $banner )
    $banner_parts = explode(” ==> “, $banner);
    $banner_img = $folder.$banner_parts[0];
    $banner_link = $banner_parts[1];

    $banner_just_img = ”;
    $banner_with_link = ‘‘ . $banner_just_img . ‘‘;
    $banner_html[] = $banner_with_link;

    $banner_html[] = ”;
    $html = $banner_html[array_rand($banner_html)];

    …and the xml is the same, so i won’t write it down…

  128. have a code to displays 40 banners one at a time it works but it only goes to the next banner when you enter the page or refresh the page does anyone know how to make it refresh to the next banner every 15 sec’s ?

    Here is the code

    It must be HTML and it cannot be script my website does not allow it
    any help would be appriciated

  129. [...] Ajax Banner Rotation [...]

  130. Hi guys,

    Can you tell me if it is possible to implement it on more than one page? If not, I will have to stick to my current banner rotator which gives me this possibility. I would like to have different types of banners on my website, not only this one: http://www.flashxml.net/banner-rotator.html which I however find very good. Waiting for your response. Thanks.

  131. When a company decides to order a banner it is very important to think of the best material to put their message on. Grommets can also be added in order to facilitate the hanging of the banner.

  132. Was Already Using a Different Banner Rotator on My Site and this looks quite impressive, giving it a try.

  133. Dion Cahn

  134. Link Lizard…

    [...]AJAX banner rotation / Stoyan’s phpied.com[...]…

  135. zero energy…

    [...]AJAX banner rotation / Stoyan’s phpied.com[...]…

  136. [...] [...]

  137. ThamKhao.vn – Thư viện tham khảo…

    [...]AJAX banner rotation / Stoyan’s phpied.com[...]…

  138. sites de busca, divulgar site, buscadores, divulgação de site, cadastrar site, Sites de busca, cadastro em Sites, inserir site, cadastrar site, cadastro web, buscadores, divulgação de site, cadastrar site, divulgar site, web marketing, Web Marketing,…

    [...]AJAX banner rotation / Stoyan’s phpied.com[...]…

  139. Paragraph writing is also a excitement, if you be
    acquainted with afterward you can write or else it is complex to write.

  140. Whats up this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG editors or
    if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

  141. My family all the time say that I am wasting my time here at net, but I know I am getting know-how every
    day by reading thes pleasant content.

  142. This is really fascinating, You are an overly skilled blogger.
    I’ve joined your rss feed and look ahead to in quest of extra of your fantastic post. Also, I have shared your web site in my social networks

    My site … this content

  143. Simply want to say your article is as surprising. The clearness on your post is just nice and i could suppose you are knowledgeable on this subject. Fine along with your permission let me to clutch your RSS feed to keep up to date with drawing close post. Thank you a million and please carry on the enjoyable work.

  144. Thanks a lot of useful informations about ajax banner rotation. Kim.

Leave a Reply