title: Block ip addresses automatically using PHP and htaccess
body: <p>I have a login system that I am trying to make as secure as possible. After ten failed attempts, I would like to block the IP address. How can I open a file in PHP and add a line to my .htaccess file to block the IP Address? Here is my .htaccess file:</p>
  
  <pre><code># Turn on RewriteEngine
  RewriteEngine on
  
  # Block IP addresses with too many failed attempts
  RewriteCond %{REMOTE_ADDR} ^217.172.179.*$ [OR]
  RewriteCond %{REMOTE_ADDR} ^217.172.180.*$
  RewriteCond %{REQUEST_URI} !/error/blocked.php$ [NC]
  RewriteRule ^(.*)$ /error/blocked.php [R,NC,L]
  </code></pre>
  
  <p>I would like the PHP file to add the line:</p>
  
  <pre><code>RewriteCond %{REMOTE_ADDR} ^IPHERE$ [OR]
  </code></pre>
  
  <p>in the appropriate spot.</p>