ok i just wiped up and tested this .htaccess file: Order Deny,Allow Allow from PUT IP HERE Deny from All HTML: And to add more just copy the allow line and change the IP
try this, just change that IP to yours: if($_SERVER['REMOTE_ADDR']!="xx.xx.xx.xx") die("you don't have access to this web");
if($_SERVER['REMOTE_ADDR']!="64.0.0.[1-254]") die("you don't have access to this web"); PHP: try that
For ranges, you need to get help from ip2long(). First you will convert your starting end ending ips to long using ip2long() and then convert IP in question to long and then compare it.
Might not be the best way to go about it, but it does work ... <?php /** * $allowed should contain all the ranges that you will allow * * note: * valid: 192.168.0.1-255 * invalid: 192.1-255.0.1-255 * * */ $allowed = array( '192.168.0.1-255', '127.0.0.1-255' ); /** STOP EDITING STOP EDITING STOP EDITING STOP EDITING STOP EDITING STOP EDITING STOP EDITING STOP EDITING **/ $continue = false ; function get_range_from_string( $string ) { if( ( $chunks = explode( ".", $string ) ) ) { foreach( $chunks as $pos => $chunk ) { if( strpos( $chunk, '-' ) !== false ) { if( list( $start, $end ) = explode( '-', $chunk ) ) { for( $i = $start; $i <= $end; $i++ ) { for( $j = 0; $j <= 3; $j++ ) { if( $pos == $j ) { $parts[$j] = $i; } else $parts[$j] = $chunks[$j]; } $ips[ ] = implode( ".", $parts ); } } } } return $ips ; } else return array( $string ); } foreach( $allowed as $range ) { foreach( get_range_from_string( $range ) as $check ) { if( $_SERVER['REMOTE_ADDR'] == $check ) { $continue = true ; } } } if( !$continue ) { die( sprintf( "<font color=red>The address %s is not allowed to browse this website</font>", $_SERVER['REMOTE_ADDR'] ) ); } /** IF EXECUTION GETS TO HERE THEN THE VISITOR IS ALLOWED **/ ?> PHP:
// Get IP function get_ip(){ $ipParts = explode(".", $_SERVER['REMOTE_ADDR']); if ($ipParts[0] == "165" && $ipParts[1] == "21") { if (getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } elseif (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } elseif (getenv("REMOTE_ADDR")) { $ip = getenv("REMOTE_ADDR"); } } else { return $_SERVER['REMOTE_ADDR']; } return $ip; } $ip = get_ip(); // Example 64.0.0.XXX $ipsubs = explode('.',$ip); for($x=0;$x<count($ipsubs)-2;$x++){ $final .= '.'.$ipsubs[$x];} if($final != '64.0.0'){ die('invalid address');} //64.0.0. if($ipsubs[count($ipsubs)-1] >= 0 && $ipsubs[count($ipsubs)-1] <= 100){ die('invalid range');} PHP: Peace,