PHP Ip bazlı engelleme

PHP ile sadece beliri ip adreslerine sahip kullanıcıların erişimine izin verme işlemi :

if( isset( $_SERVER["HTTP_CLIENT_IP"] ) ) {
  $remoteIP = $_SERVER["HTTP_CLIENT_IP"];
} elseif( isset( $_SERVER["HTTP_X_FORWARDED_FOR"] ) ) {
  $remoteIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
  $remoteIP = $_SERVER["HTTP_CF_CONNECTING_IP"];
} else {
  $remoteIP = $_SERVER["REMOTE_ADDR"];
}
 
$ips[] = '111.111.11.11';
 
if (!in_array($remoteIP , $ips)) {
    header('HTTP/1.0 403 Forbidden');
    exit();
}

Yorum Yap


Not - Bunları KullanabilirsinizHTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">