function system_ban_ip
Search API
| 7.x system.module | system_ban_ip($ip, $comment = "") |
Adds IP address to our banned_ip list.
Parameters
unknown $ip:
2 calls to system_ban_ip()
- system.module in modules/
system/ system.module - system_check_should_ban_ip in modules/
system/ system.module - This is called by theme.inc's functions display_not_found and display_access_denied.
File
- modules/
system/ system.module, line 800
Code
function system_ban_ip($ip, $comment = "") {
$ban_ip_file_path = fp_get_files_path() . '/private/banned_ips.txt';
$res = file_put_contents($ban_ip_file_path, "\n$ip", FILE_APPEND | LOCK_EX);
if ($res === FALSE) {
watchdog("ban_ip", "Unable to write to ban ip file. Possible file permission issue?", array(), WATCHDOG_ERROR);
print "failed";
return FALSE;
}
// Reset our apcu cache, if installed.
if (function_exists('apcu_store')) {
apcu_delete('banned_ips'); // force reload of banned ips next time a page is loaded.
}
// Also put in our table with current timestamp, so cron can expire it later (if setup).
// Use REPLACE to avoid mysql errors for duplicate IPs
db_query("REPLACE INTO banned_ips (ip_address, posted_ts) VALUES (?, ?)", array($ip, time()));
watchdog("ban_ip", "Banned IP address: %ip; %comment", array("%ip" => $ip, "%comment" => $comment));
return TRUE;
}
