<?php
if(!isset($root)){ // handling if you're looking at the literal bg.php page - it's not being loaded by another page
	$root = "../";
}

$dir = $root."images/backgrounds/";
$files = scandir($dir);
$images = array_diff($files, array('.', '..'));
$name = $images[array_rand($images)];
// open the file in a binary mode
$fp = fopen($dir . $name, 'rb');

// send the right headers
header('Cache-Control: public'); // HTTP 1.1
header('Pragma: cache'); // HTTP 1.0
header('Expires: 0'); // Proxies
header('Content-Type: image/gif');

// dump the picture and stop the script
fpassthru($fp);
exit;
?>
