<?php
/*Skrypt pochodzi z ksi±¿ki "PHP. 101 praktycznych skryptów"
  autor: Marcin Lis                    http://marcinlis.com*/

$dir = "./banners/";
function printBannerName($dir)
{
  if(!($fd = opendir($dir))){
    return false;
  }
  $arr = array();
  while (($file = readdir($fd)) !== false){
    if($file != "." && $file != "..")
      $arr[] = $file;
  }
  closedir($fd);
  srand((float) microtime() * 10000000);
  $name = $arr[array_rand($arr)];

  if($name != "")
    echo("<img src=\"$dir$name\" alt=\"reklama\">");
  else
    return false;
  return true;
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title>Moja strona WWW</title>
</head>
<body>
<div>
<?php if(!printBannerName($dir)) echo("Brak bannera"); ?>
</div>
</body>
</html>
