Home

bernieberg edited this page Jul 29, 2011 · 2 revisions
Clone this wiki locally

This is how I use it: just look at the lines that have comments above them, i left the rest in there just for context.

$phpids_file_root = dirname(__FILE__);

$phpids_html_fields = array();
$phpids_ignore_fields = array( 'REQUEST.item_description',
'POST.item_description',
'REQUEST.category_description',
'POST.category_description');
// this is the class that handles ip blocking
require_once 'Ips.php';
$phpids_user_ip = $_SERVER['REMOTE_ADDR'];
// arguments are $log_file, $block_duration=7200, $block_hits=5
$phpids_ips = new IDS_Ips($phpids_file_root.'/IDS/tmp/ips.txt');

set_include_path(
get_include_path()
. PATH_SEPARATOR
. $phpids_file_root
);

require_once 'IDS/Init.php';
$phpids_request = array(
'REQUEST' => $_REQUEST,
'GET' => $_GET,
'POST' => $_POST,
'COOKIE' => $_COOKIE
);

$phpids_init = IDS_Init::init($phpids_file_root.'/IDS/Config/Config.ini');

$phpids_config = $phpids_init->getConfig();
$phpids_config["General"]["base_path"] = $phpids_file_root.'/IDS/';
$phpids_config["General"]["html"] = $phpids_html_fields;
$phpids_config["General"]["exceptions"] = $phpids_ignore_fields;
$phpids_init->setConfig($phpids_config, true);

$phpids_ids = new IDS_Monitor($phpids_request, $phpids_init);
$phpids_result = $phpids_ids->run();

if (!$phpids_result->isEmpty()) {
// log a hit for this ip address
$phpids_ips->logHit($phpids_user_ip);
// write the log file
$phpids_ips->writeLog();
exit;
}

if ($phpids_ips->isBlocked($phpids_user_ip)) {
// don't let this ip address continue
exit;
}