Hi Guys,
Just got into phpids yesterday. I needed a way to protect some of the older sites I manage. Seems to work great, but I wanted a way to ban ip addresses without too much hassle. So I wrote this simple class to handle it:
https://github.com/bernieberg/phpids...master/Ips.php
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.
If you look at the source, it should make sense, it's pretty simple. I'm sorry if there is something out there that already does this and I missed it.Code:$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; }
Thanks!
--
bernie


Zitieren
Lesezeichen