$requri = getenv ("REQUEST_URI");
$httpref = getenv ("HTTP_REFERER");
// log all errors refered from terragalleria.com
if (preg_match('/^http:\/\/(www.)?terragalleria.com/',$httpref)) {
$dt = date("F j, Y H:i");
$ip = getenv ("REMOTE_ADDR");
$fp = fopen("/home/tega/logs/not_found_log","a") or die("cannot open file");
fwrite($fp,"[$dt] [$ip] $requri referer: $httpref\n");
fclose($fp);
}
$url = "";
if (preg_match('/\W([a-zA-Z]{4}\d{4}\d?(-bw)?)(\D|$)/',$requri,$matches) == 1) {
$ref=$matches[1];
if (preg_match('/black-white/',$requri) && !preg_match('/-bw$/',$ref)) {
$ref .= "-bw";
}
require('/home/tega/httpdocs/scripts/mysql.php');
mysql_select_db('photo', $mysql) or die ('Could not select database');
$result = mysql_query("select url,status from images where ref = '$ref'",$mysql)
or die("$query : failed - " . mysql_errno() . " : " . mysql_error());
$array = mysql_fetch_row($result);
$status = $array[1];
if (strlen($status) > 7) {
$result1 = mysql_query("select url from images where ref = '$status'",$mysql)
or die("$query : failed - " . mysql_errno() . " : " . mysql_error());
$array = mysql_fetch_row($result1);
}
$url = $array[0];
}
if ($url != "") {
header("Location: /$url");
} else {
header("Location: /?not_found=$requri");
}
?>