|
Guide to Bells
|
|
// find out the domain:
$domain = $_SERVER['HTTP_HOST'];
// find out the path to the current file:
$path = $_SERVER['SCRIPT_NAME'];
// find out the QueryString:
$queryString = $_SERVER['QUERY_STRING'];
// put it all together:
$urlxyz = "http://" . $domain . $path . "?" . $queryString;
function c2c_random_file( $dir, $extensions='', $reftype='relative', $exclusions='' ) {
$files = array();
$i = -1;
$pattern = '/.*';
if ( !empty($extensions) ) $pattern .= '\.(' . implode('|', explode(' ', $extensions)) . ')';
$pattern .= '$/i';
$dir = trim($dir, '/');
$handle = opendir($dir);
$exclusions = empty($exclusions) ? array() : array_map("basename", $exclusions);
while ( false != ($file = readdir($handle)) ) {
if ( is_file($dir . '/' . $file) && preg_match($pattern, $file) && !in_array($file, $exclusions) ) {
$files[] = $file;
++$i;
}
}
closedir($handle);
if ( empty($files) ) return;
mt_srand((double)microtime()*1000000);
$rand = mt_rand(0, $i);
if( !empty($dir) ) $dir .= '/';
if ( 'url' == $reftype ) {
return '/' . $dir . $files[$rand];
} elseif ( 'absolute' == $reftype ) {
return $dir . $files[$rand];
} elseif ( 'filename' == $reftype ) {
return $files[$rand];
} else {
// Need to obtain location relative to root of domain (in case site is based out of subdirectory)
preg_match("/^(https?:\/\/)?([^\/]+)\/?(.+)?$/", $urlxyz, $matches);
$relpath = isset($matches[3]) ? '/' . $matches[3] : '';
return $relpath . $dir . $files[$rand];
}
} //end c2c_random_file()
//include(c2c_random_file('articles/html', 'html'));
$filler=c2c_random_file('articles/html', 'html');
include($filler);
?>
|
|
|