title: How can I get user's IP and block it?
body: <p>I'm trying to block some of my website's users. Well I need two things:</p>
  
  <ul>
  <li>getting user's IP</li>
  <li>blocking it</li>
  </ul>
  
  <p>I've searched about them. And I understand I have to get user's IP <a href="https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php#3003233">like this</a>:</p>
  
  <pre><code>$ip = $_SERVER['REMOTE_ADDR'];
  // or sometimes $_SERVER['HTTP_X_FORWARDED_FOR']
  </code></pre>
  
  <p>And I have to block it <a href="https://stackoverflow.com/questions/2869893/block-specific-ip-block-from-my-website-in-php#2869931">like this</a>:</p>
  
  <pre><code>$network = ip2long("10.12.0.0");
  $mask = ip2long("255.255.0.0");
  $ip = ip2long($_SERVER{'REMOTE_HOST'});
  if (($network &amp; $mask) == ($ip &amp; $mask)) {
    die("Unauthorized");
  }
  </code></pre>
  
  <p>As you see, for blocking an IP, it uses <code>$_SERVER{'REMOTE_HOST'}</code>. Well that's the different between <code>$_SERVER{'REMOTE_HOST'}</code> and <code>$_SERVER['REMOTE_ADDR']</code>? And which one is containing the IP ?</p>