Location: PHPKode > projects > Admbook > admin/ip-ban-add.php
<?php
	class Timer {
		var $startTime;
		var $endTime;
		function start() {
			$this->startTime = gettimeofday();
		}
		function stop() {
			$this->endTime = gettimeofday();
		}
		function elapsed() {
			return (($this->endTime["sec"] - $this->startTime["sec"]) * 1000000 + ($this->endTime["usec"] - $this->startTime["usec"])) / 1000000;
		}
	}
	$timer = new Timer();
	$timer->start();
	session_start();
	include("../settings-data.php");
	include("../lib.php");
	checkPermissions($login, $password);
	include("../banned-ip-data.php");
	if (!isset($error))
		$error = "";
	if (!isset($style))
		$style = "";
	session_register("error");
	session_register("style");
	session_register("ip");
	if (!isset($banned))
		$banned = array();
	if (!isset($ip))
		$ip = "";
	$banIp = explode(",",$ip);
	for($i = 0; $i < sizeof($banIp); $i++)
	{
		$banIp[$i] = trim($banIp[$i]);
		if (!validIp($banIp[$i]))
		{
			$error .= "Wrong Ip<br/>";
			$style .= "\n.ip {\n\tcolor : ".$constant['error-color']."\n}\n";
			break;
		}
		$banIp[$i] = ip2long($banIp[$i]);
		if (in_array($banIp[$i], $banned))
		{
			$error .= "This ip is present<br/>";
			$style .= "\n.ip {\n\tcolor : ".$constant['error-color']."\n}\n";
			break;
		}
	}
	if ($error != "")
	{
		Header("Location: ip-ban.php?page=".$page);exit;
	}
	$newIp = "<?php\n";
	$banIp = array_merge($banIp, $banned);
	$banIp = array_values(array_unique($banIp));
	for($i = 0; $i < sizeof($banIp); $i++)
	{
		$newIp .= "\t\$banned[] = \"".$banIp[$i]."\";\n";
	}
	$newIp .= "?>";
	reWriteDataInFile ($newIp,"../banned-ip-data.php");
	session_unregister("error");
	session_unregister("style");
	session_unregister("ip");
	$timer->stop();
	Header("Location: ip-ban.php?".$timer->elapsed());exit;
?>
Return current item: Admbook