+ Antworten
Ergebnis 1 bis 3 von 3

Thema: IP Blocker

  1. #1
    Neuer Benutzer
    Registriert seit
    29.07.2011
    Beiträge
    1
    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.

    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;
    }
    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.


    Thanks!
    --
    bernie

  2. #2
    Moderator Avatar von .mario
    Registriert seit
    30.05.2007
    Beiträge
    924
    That's pretty interesting! I'll have a close look before our next release and consider mentioning it in the release post.

    Cheers,
    .mario

  3. #3
    Neuer Benutzer
    Registriert seit
    16.04.2012
    Beiträge
    6
    Hi!

    Any update on this?

    Thanks!

+ Antworten

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein