Location: PHPKode > scripts > Login Ban > lb.class.php
<?php


/**
* Login ban class
* @By Mohammed Cherkaoui
* @Mail duhok-hide@address.com
*/

class Login_Ban
{




	/**
	* The number of attempts
	*
	* @var	int
	*/
	
	var $Limit_attempts = '3';
	
	/**
	* The time of ban (Minutes)
	*
	* @var	int
	*/
	
	var $Ban_time = '15';

	/**
	* Constructor.
	* @param	Limit attemps to ban
	* @param 	time of ban (Minutes)
	*/

	function Login_Ban($Limit_attempts = '3', $Ban_time = '15')
	{
	$this->Limit_attempts = $Limit_attempts;
	$this->Ban_time = $Ban_time;
	}
	
	/**
	* Add the cookies
	* @param	the name if cookie
	* @param 	the value
	*/
	function SetCookies($CookiesName, $Value)
	{
	setcookie($CookiesName, $Value,time() + 60 * 60 * 24 * 30, NULL ,NULL, NULL, TRUE); 
	}
	
	/**
	* Add new attemp.
	*/

	function Set_Attemp()
	{
	if(! isset($_COOKIE['login_attemp']))
	{
	$this->SetCookies('login_attemp', '1');
	$this->SetCookies('attemp_date', time());
	} elseif(isset($_COOKIE['login_attemp']))
	{
	$this->SetCookies('login_attemp', $_COOKIE['login_attemp'] + 1);
	$this->SetCookies('attemp_date', time());
	}
	}
	
	
	/**
	* To verify that it has been banned
	* 
	*/
	
	function Banned()
	{
	if(! isset($_COOKIE['login_attemp']))
	{
	return false;
	} elseif(isset($_COOKIE['login_attemp']))
	{
	if(($_COOKIE['login_attemp'] == $this->Limit_attemps || $_COOKIE['login_attemp'] > $this->Limit_attemps))
	{
	if($this->Ban_time * 60 + time() == $_COOKIE['attemp_date'] || $this->Ban_time * 60 + time() * 60 > $_COOKIE['attemp_date'])
	{
	return true;
	} else
	{
	return false;
	}
	} else
	{
	return false;
	}
	}
	}
	
	/**
	* Delete the attemper cookies.
	*/
	
	function mkempty()
	{
	$this->SetCookies('login_attemp', '');
	$this->SetCookies('attemp_date', '');
	}
	

}




?>
Return current item: Login Ban