PHP redirect based on IP addresses -


i need show content specific range of ip addresses , others want redirect.

i have found code checking ip address:

<?php   $ip_ban = array(); $ip_ban[] = "10.10.*.*";  $ip_ban[] = "10.111.111.10";  if(in_array($_server['remote_addr'],$ip_ban))  {     header("location: http://www.yahoo.com/");  }  else {     //do loop through bans:     foreach($ip_ban $ban)      {         if(eregi($ban,$_server['remote_addr']))          {             header("location: http://www.yahoo.com/");          }          //finished loop     }  } ?> 

the code works, redirects yahoo, need show content instead of redirection. , redirect other ip addresses.

how can modify script?

your approach strange. in_array matches against wildcard ips nothing. think of ips preg patterns.

<?php   $ip_ban = [   "10\.10\.\d\.\d";    "10\.111\.111\.10" ];  foreach($ip_ban $ban)  {     if(\preg_match("/$ban/", $_server['remote_addr']))      {         header("location: http://www.yahoo.com/");         exit;     } }  echo "not banned"; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -