http://www.backlog.cn/index.php/forums/viewthread/17/
以前用js来更换Banner的背景以及主题,可是每次登陆的时候由于登陆页面是用js直接跳转上一页的,所以每次自动运行到首页的scripts脚本就过不去了,为此我苦恼了好久.
现在,问题终于解决了.直接用php程序来随机调用Banner,真是方便啊!
现在贡献给需要的同志吧:
首先,将下列代码转寸为php程序.
代码:
<?php
$folder = '这里放你需要调用Banner的文件夹,如果是与Randombanner.php同一个文件夹里就保持空白';
// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along
header('Location: '.$folder.$files[$rand]); // Voila!
?>
希望大家喜欢啊!









还有三篇:随机显示Banner.如何在首页调用论坛最新帖子? 如何在首页显示画廊里的图片?









平板模式