Looie
12-22-2007, 01:49 PM
I only started with PHP a bit ago, I don't know much, but I had an idea and just wanted to see if it would work
<?php
// Mirror server
$mirror = 'http://www.mirrorserver.com/';
// Files directory
$dir = 'x71';
// Where to get the current server load
$getLoad = '/proc/loadavg';
//Where to get the mirror server's load
$getLoad2 = 'load.php';
// Gets the name of the file requested
$file = $_GET['file'];
// Checks to make sure the request is valid, and stops executing code if it isn't
if ( strstr($file, '/') || empty($file) || !strstr($file, '.') )
exit;
// Gets the server load for the current server
$handle = fopen($getLoad, 'r');
$load = fread($handle, '5');
// Gets the server load for the mirror server
$handle = fopen($mirror. $getLoad2, 'r');
$load2 =fread($handle, '5');
// Checks to see if the mirror server has a lower load and redirects if it does
if ($load > $load2)
header('location: ' . $mirror . '?file=' . $file);
// Gets the proper location of the file
$newfile = '/filesystem/path/to/file/' . $dir . '/' . $file;
// Checks to see if the file exists, and redirects if it does
if ( file_exists($newfile) )
header('location: /' . $dir . '/' . $file);
else
echo 'Error.';
?>
Can anyone tell me if there's a problem, what it is, and how it can be fixed. Also, is it secure?
<?php
// Mirror server
$mirror = 'http://www.mirrorserver.com/';
// Files directory
$dir = 'x71';
// Where to get the current server load
$getLoad = '/proc/loadavg';
//Where to get the mirror server's load
$getLoad2 = 'load.php';
// Gets the name of the file requested
$file = $_GET['file'];
// Checks to make sure the request is valid, and stops executing code if it isn't
if ( strstr($file, '/') || empty($file) || !strstr($file, '.') )
exit;
// Gets the server load for the current server
$handle = fopen($getLoad, 'r');
$load = fread($handle, '5');
// Gets the server load for the mirror server
$handle = fopen($mirror. $getLoad2, 'r');
$load2 =fread($handle, '5');
// Checks to see if the mirror server has a lower load and redirects if it does
if ($load > $load2)
header('location: ' . $mirror . '?file=' . $file);
// Gets the proper location of the file
$newfile = '/filesystem/path/to/file/' . $dir . '/' . $file;
// Checks to see if the file exists, and redirects if it does
if ( file_exists($newfile) )
header('location: /' . $dir . '/' . $file);
else
echo 'Error.';
?>
Can anyone tell me if there's a problem, what it is, and how it can be fixed. Also, is it secure?
