Jump to content

Extension talk:IPexception

Add topic
From mediawiki.org
Latest comment: 13 years ago by ATHeinrich in topic Host Exception

this extension is so good. but it can only set restriction to a few ip, if we need a range of ip, can change if (in_array($_SERVER['REMOTE_ADDR'], $IPexception)) { $IPexceptionPermission = $IPexceptiontrue; }


to

  	if (ip2long($_SERVER['REMOTE_ADDR'])<=ip2long($IPexception[1]) and ip2long($_SERVER['REMOTE_ADDR'])>=ip2long($IPexception[0]) ) {

$IPexceptionPermission = $IPexceptiontrue; }

Host Exception

[edit]

I altered the IPexception function so it will also accept hostnames:

function IPexception($IPexception, $IPexceptiontrue, $IPexceptionPermission){	
	if (isset($IPexception)){
		# if the ip number is found in the array then return true
		if (in_array($_SERVER['REMOTE_ADDR'], $IPexception)) {
			$IPexceptionPermission = $IPexceptiontrue;
		}
		# if the host is found in the array then return true
		else {
			foreach ($IPexception as $key => $hostname){
				$IPexception[$key]=strtolower($hostname);
			}
			if (in_array(strtolower($_SERVER['REMOTE_HOST']), $IPexception)){
				$IPexceptionPermission = $IPexceptiontrue;
			}
		}
	}
 
	return $IPexceptionPermission;
}

--ATHeinrich 11:17, 16 February 2011 (UTC)Reply