| |

Blokuojam IP adresus naudojant PHP

Pateikiamas PHP kodo pavyzdys, kaip galime filtruoti IP adresus.Jei norime blokuoti IP adresus pagal šabloną, pvz.:

// array's of banned IP addresses
$bannedIP = array("^10.999.00.*", "^99.88.77.*", "192.168.0.1", "^66.77.*.*");
if(in_array($_SERVER['REMOTE_ADDR'],$bannedIP)) {
     // this is for exact matches of IP address in array
     header("Location: http://www.domain.com");
     exit();
} else {
     // this is for wild card matches
     foreach($bannedIP as $ip) {
          if(eregi($ip,$_SERVER['REMOTE_ADDR'])) {
               header("Location: http://www.domain.com");
               exit();
          }
     }
}
Kviečiu įvertinti įrašą!
[Viso: 0 Vidurkis: 0]

Similar Posts

Parašykite komentarą

El. pašto adresas nebus skelbiamas.

+ 41 = 45