(now() - '48 hrs'::interval)", array($mirror)); if (pg_num_rows($res) != 1) { echo "Mirror not found."; exit(1); } $rs = pg_fetch_row($res, 0); $host = $rs[0]; $port = $rs[1]; $path = $rs[2]; $altroot = $rs[3]; if ($file[0] != '/') { $file = '/' . $file; } if ($path[0] != '/') { $path = '/' . $path; } if ($path[strlen($path)-1] == '/') { $path = substr($path, 0, strlen($path)-1); } if ($type == 'h') { // Construct http url if ($altroot == 't') { $url = "http://" . $host . $file; } else { $url = "http://" . $host . $path . $file; } } else { // Construct ftp url if ($rs[1] > 0 && $rs[1] != 21) { echo "Port changes not currently supported"; } else { $url = "ftp://" . $host . $path . $file; } } $ip = $_SERVER['REMOTE_ADDR']; $ip = preg_split('/[.]+/', $ip); $ipnumber = (double) ($ip[0] * 16777216) + ($ip[1] * 65536) + ($ip[2] * 256) + ($ip[3]); @pg_query_params($db, "INSERT INTO clickthrus (scheme, host, path, country) VALUES ($1,$2, $3, (SELECT countrycode FROM iptocountry WHERE $4 BETWEEN startip AND endip LIMIT 1))", array( $type=='h'?'http':'ftp', $host, ($type=='h'&&$altroot=='t')?$file:($path . $file), $ipnumber )); header("Location: " . $url); exit; ?>