Topics

Ban IP from logging in for 5 minutes after 10 failed logins

Ban IP from logging in for 5 minutes after 10 failed logins


if( login_limit() )
   die( 'Your IP has been banned from logging in for the next 5 minutes' );



/*
 * Counts login times by same IP 
 * returns true if limit reached or false if not 
 */
function login_limit(){
    //get real IP if user behind proxy noted by Sebastian Enger
    $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
    
    //user still banned from login
    if( _cache( $ip . 'banned' ) )
        return true;

    //number of seconds 
    $sec = 30;
    //find ip info array in cache saved less than $sec ago
    if( ($ip_info=_cache( $ip ))  && $ip_info[0] > time()-$sec ){
        
        //user login 10 times during last $sec 
        if(  $ip_info[1] > 10 ){
            //ban user ip for the next 5 minutes
            _cache( $ip . 'banned', 1, 0, 60*5 );
            _cache( $ip, -1 );
            return true;
        }
        //increase login retries +1 
        _cache( $ip, array(  $ip_info[0],   ++$ip_info[1] ), 0, $sec );
        return false;
        
    }
        
    //add ip info to cache
    _cache( $ip, array( time(), 1 ), 0, $sec );
    return false;
}

function _cache( $name, $val=NULL, $ttl=false ){
        //memcached
	global $mcdb;
	if(empty($mcdb) ) 
		$mcdb = memcache_connect('unix:///etc/sockets/memcached.sock', 0);
	
	if($val === -1){
		return memcache_delete($mcdb,$name);
	}elseif( $val !== NULL ){
		return memcache_set($mcdb,$name,$val, false, $ttl);
	}else{
		$retval = memcache_get($mcdb,$name);
		return  $retval ? $retval : NULL;
	}

}

Support Egypt Revolution

Show your support for the Egyptian revolution by adding this code to your website and blog

<img border="0" id="corner-ad" src="http://gadelkareem.com/tmp/jan25.jpg" width="222" height="111" /> <style>#corner-ad { 
    display: block;  
    width: 222px;  
    height: 111px;  
    position: fixed;  
    top: -16px;  
    right: -70px;  
    -webkit-transform: rotate(45deg);  
    -moz-transform: rotate(45deg);  
    -o-transform: rotate(45deg);  
} 
#corner-ad {  
    top: -80px\9;  
    right: -70px\9;  
    *right: -70px;  
    filter:  progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476);  
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)";  
    zoom: 1;  
}
</style>

A Demo of this code can be seen on the top right of this page

Convert vBulletin DB encoding to UTF-8

great help @ http://mansurovs.com/tech/converting-vbulletin-to-utf-8

these are the exact commands that worked for me

jQuery plugin : monnaTip 0.1

This the simplest tooltip jQuery plugin you can find around.

    features:
  • takes advantage of live(), mouseenter and mouseleave methods
  • tracks mouse movement
  • right and bottom viewport border tracking
  • can be applied on any element

DemodownloadGoogle codeGitHub

use name attribute for input instead of id for use with label

you need Jquery:

<label for="myinput"></label><input name="myinput" type="text" value="text here" />
$('label').live('click', function(e){
        if( $(e.target).is(':input') ) return;
        var i = $(':input[name="' + $(this).attr('for') + '"]')
        i.is(':checkbox') ? i.attr('checked', !i.attr('checked') ) : i.focus().select();
    })