ArcticFox
01-24-2007, 08:07 AM
I've got a logging script that keeps hanging the site. When it's installed, the page takes forever to load. When removed, the page shows instantly.
<?php
$server = 'localhost'; // MySQL hostname
$username = 'username'; // MySQL username
$password = 'password'; // MySQL password
$dbname = 'dbname'; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';
list($countryName) = mysql_fetch_row(mysql_query($sql));
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['HTTP_X_FORWARDED_FOR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';
list($countryName2) = mysql_fetch_row(mysql_query($sql));
$ti = date("l, F jS Y - g:ia");
$ip = getenv("REMOTE_ADDR");
$pr = getenv("HTTP_X_FORWARDED_FOR");
$ac = getenv("HTTP_ACCEPT");
$la = getenv("HTTP_ACCEPT_LANGUAGE");
$re = getenv("HTTP_REFERER");
$br = getenv("HTTP_USER_AGENT");
$se = getenv("SERVER_NAME");
$ho = gethostbyaddr(getenv("REMOTE_ADDR"));
$fp = fopen("./logs.php", "a+");
if (strstr($_SERVER["REMOTE_ADDR"], "127.0.0.0")) {
fputs($fp, "
<font style=color:#00cc00;font-variant:small-caps;font-size:14px;font-weight:bold;>AF - MAIN INDEX PAGE</font><br />
<b>Time:</b> $ti<br />
<b>Browser Type:</b> $br<br />
<b>WEBMASTER</b><br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}
else {
fputs($fp, "
<font style=color:#0099ff;font-variant:small-caps;font-size:14px;font-weight:bold;>MAIN INDEX PAGE</font><br />
<b>Time:</b> $ti<br />
<b>IP Address:</b> $ip - $countryName<br />
<b>Match Proxy:</b> <u>$pr</u> - $countryName2<br />
<b>HTTP Accept:</b> $ac<br />
<b>Languages:</b> $la<br />
<b>Referer URL:</b> <a target=_blank href=$re>$re</a><br/>
<b>Browser Type:</b> $br<br />
<b>Host Name:</b> $ho<br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}
if (strstr($_SERVER["HTTP_REFERER"], "codingforums")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "dynamicdrive")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "sitepoint")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.172.242.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.103.132.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "69.234.44.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "204.246.129.196")) {header("location: error403.php");}
?>
I don't know what's causing it. I took out the part that pulls from the db, but that had no effect. The logs.php page is nearly empty, so it's not like that's the issue.
Ideas?
<?php
$server = 'localhost'; // MySQL hostname
$username = 'username'; // MySQL username
$password = 'password'; // MySQL password
$dbname = 'dbname'; // MySQL db name
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';
list($countryName) = mysql_fetch_row(mysql_query($sql));
$db = mysql_connect($server, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = 'SELECT
c.country
FROM
ip2nationCountries c,
ip2nation i
WHERE
i.ip < INET_ATON("'.$_SERVER['HTTP_X_FORWARDED_FOR'].'")
AND
c.code = i.country
ORDER BY
i.ip DESC
LIMIT 0,1';
list($countryName2) = mysql_fetch_row(mysql_query($sql));
$ti = date("l, F jS Y - g:ia");
$ip = getenv("REMOTE_ADDR");
$pr = getenv("HTTP_X_FORWARDED_FOR");
$ac = getenv("HTTP_ACCEPT");
$la = getenv("HTTP_ACCEPT_LANGUAGE");
$re = getenv("HTTP_REFERER");
$br = getenv("HTTP_USER_AGENT");
$se = getenv("SERVER_NAME");
$ho = gethostbyaddr(getenv("REMOTE_ADDR"));
$fp = fopen("./logs.php", "a+");
if (strstr($_SERVER["REMOTE_ADDR"], "127.0.0.0")) {
fputs($fp, "
<font style=color:#00cc00;font-variant:small-caps;font-size:14px;font-weight:bold;>AF - MAIN INDEX PAGE</font><br />
<b>Time:</b> $ti<br />
<b>Browser Type:</b> $br<br />
<b>WEBMASTER</b><br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}
else {
fputs($fp, "
<font style=color:#0099ff;font-variant:small-caps;font-size:14px;font-weight:bold;>MAIN INDEX PAGE</font><br />
<b>Time:</b> $ti<br />
<b>IP Address:</b> $ip - $countryName<br />
<b>Match Proxy:</b> <u>$pr</u> - $countryName2<br />
<b>HTTP Accept:</b> $ac<br />
<b>Languages:</b> $la<br />
<b>Referer URL:</b> <a target=_blank href=$re>$re</a><br/>
<b>Browser Type:</b> $br<br />
<b>Host Name:</b> $ho<br />
<hr noshade size=1 width=50% align=left />
");
fclose($fp);}
if (strstr($_SERVER["HTTP_REFERER"], "codingforums")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "dynamicdrive")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["HTTP_REFERER"], "sitepoint")) {header("location: http://www.BaseStationZero.com/HOLD/ ");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.172.242.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "82.103.132.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "69.234.44.")) {header("location: error403.php");}
if (strstr($_SERVER["REMOTE_ADDR"], "204.246.129.196")) {header("location: error403.php");}
?>
I don't know what's causing it. I took out the part that pulls from the db, but that had no effect. The logs.php page is nearly empty, so it's not like that's the issue.
Ideas?