title: How do I allow only certain IP's to view webpages?
body: <p>I'm trying to get a PHP script to work where it compares the IP of the person against a text file(one IP per line). If the person's IP is not in the text file, then he gets redirected to declined.html. I know I could use .htaccess for this but the IP list could get really, really long. </p>
  
  <p>This is the code that I have so far:</p>
  
  <pre><code>&lt;?php
  $ipArray = file('ip.txt');
  unset($allowed);
  foreach ($ipArray as $ipTest) if (substr_count($_SERVER['REMOTE_ADDR'],trim($ipTest))     != "0") $allowed = true;
  if ($allowed != true) {
  header('location: /declined.html');  // the banned display page
  die();
  }
  ?&gt;
  </code></pre>
  
  <p>I want to be able to call this script in every page that I only want certain IP's to see, this is what I'm trying to call it with:</p>
  
  <pre><code>&lt;? include('ip_allow.php'); ?&gt;
  </code></pre>
  
  <p>When I call the PHP script in the HTML page when my IP is NOT in ip.txt, it does not redirect me to /declined.html! How can I fix this? Again, my question is not how to use .htaccess, but how to fix my script! Thanks.</p>