PHP

Soldato
Joined
8 Oct 2005
Posts
4,184
Location
Midlands, UK
Hi,

I have a simple ad rotation script that displays a different ad upon a page refresh. The ads are coming from a text file where the actual is just a bit of very simple html code. The PHP code is below.

What I would like to do is refrssh the ad every few seconds. Any ideas how I do this in PHP?

PHP:
$file = join ('', file ('../../inc/banners2.txt'));	
	$ad = split("~",$file);
	$bannerid = rand(0,(count($ad)-1));
	echo $ad[$banner_id];

Thanks
 
Well I meant a biot of simple javascript, nothing asynchronous :)
It'll certainly need an XmlHTTPRequest at the least. :)

Code:
function onLoad() {
  setInterval(30, "changeAd()");
}

if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
  try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
  throw new Error( "This browser does not support XMLHttpRequest." )
};


function changeAd() {
  var http = new XMLHttpRequest();
  http.open("GET", "http://www.yourdomain.com/advert.php");
  http.onreadystatechange = function () {
    if (http.readystate == 4) {
      document.getElementById("ad").innerHTML = http.responseText;
    }
  }
}
 
Back
Top Bottom