2
此腳本很好。我把它稱爲我的腳本之上。但是,如果沒有被禁止用戶進入該網站,他們得到:嘗試獲取非對象的屬性
Notice: Trying to get property of non-object in index.php on line 20
功能:
// Check if conecting user is banned. If ban has expired delete row.
function check_bans()
{
// IP address
$user_ip = $_SERVER['REMOTE_ADDR'];
$query = mysql_query("SELECT ip, expire FROM bans WHERE ip = '$user_ip'");
$row = mysql_fetch_object($query);
$expire = $row->expire ? date('M d Y H:i', $row->expire) : 'Never';
// Did we find a match?
if (mysql_num_rows($query)) {
// Has this ban expired? Then delete and let user inside.
if ($row->expire != '' && $row->expire <= time())
mysql_query("DELETE FROM bans WHERE ip = '$user_ip'") or die (mysql_error());
else
die("<h1 align=\"center\" style=\"color:maroon\">You have been IP banished. Ban will be lifted: $expire</h1>");
}
}
其實我覺得'if(mysql_num_rows($ query))'是多餘的。 – 2010-07-22 00:33:56
@Felix - 你是對的,它看起來如此。將刪除。 – karim79 2010-07-22 00:36:53