PHP Tutorial : Block certain IP Address

I see this seems to be a very hot subject on the folks searching for php scripts and help. Its not really big deal to block a certain visitor IP Address. It works like : first you need to detect their IP, then you just send him a 404 not found header. Have a look:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$blocked = "127.0.0.1";

if($ip == $blocked) {
header("HTTP/1.0 404 Not Found");
exit();
}
?>
This entry was posted in Usefull PHP and tagged , , , , , , , , , , . Bookmark the permalink.

5 Responses to PHP Tutorial : Block certain IP Address

  1. Asp.NET Dersleri says:

    ooo thanks.

    i will follow this blog.

  2. admin says:

    ooo cool, glad to hear

  3. mic says:

    where shall I place these codes? thanks!

  4. admin says:

    into head of your files, before code

  5. Hi, cool post. I have been wondering about this topic,so thanks for writing.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>