function get_random_image() { $files = scandir($_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/bg'); $count = count($files); srand(time()); $img = $files[rand(0,$count)]; if(($count-2) <= 0) return FALSE; return $img; } function get_random_image_ex() { do { $img = get_random_image(); if($img === FALSE) return FALSE; if($img != '.' && $img != '..' && !empty($img)) break; }while(true); return FULL_BASE_URL.'/img/bg/'.$img; } $str = get_random_image_ex(); if($str!== FALSE) { $str = '<style type="text/css"> body {background-image: ' . $str . ' } </style> '; $vbulletin->templatecache['headinclude'] .= addcslashes($str, '\\"');