Tuesday, September 28, 2010

Test PHP script to block IP address

According to Blog Technics: Script To Block IP Addresses on Blogspot, all one need to do is to upload a PHP script to a file host which allows PHP files, then add another script to just before </head> in the template (or add them to a HTML/Javascript gadget).

This was exactly what was done to Medical Information as a test to ban myself (IP Address 110.159.247.42) from that blog.

Let's go through what was done for the test. The following script:

<?php
/*
Blogspot IP address blocker. Provided by www.blogtechnics.info
*/
$iplist = array("IP Address 1","IP Address 2","IP Address 3"); // the list of banned IPs

$ip = getenv("REMOTE_ADDR"); // get the visitors IP address
// echo "$ip";
$found = false;
foreach ($iplist as $value) { // scan the list
if (strpos($ip, $value) === 0){
$found = true;
}
}

if ($found == true) {
echo "top.location = \"error.html\";\n"; // page to divert to
}

?>


was replaced with

<?php
/*
Blogspot IP address blocker. Provided by www.blogtechnics.info
*/
$iplist = array("110.159.247.42"); // the list of banned IPs

$ip = getenv("REMOTE_ADDR"); // get the visitors IP address
// echo "$ip";
$found = false;
foreach ($iplist as $value) { // scan the list
if (strpos($ip, $value) === 0){
$found = true;
}
}

if ($found == true) {
echo "top.location = \"error.html\";\n"; // page to divert to
}

?>


The above in a Notepad file (ASCII) was saved with a .php extension and uploaded to www.110mb.com/. The URL of the uploaded file is

http://bloggerfordummies.110mb.com/BlogspotIPblocker.php

Accordingly I am supposed to substitute BlogspotIPblocker.php in the code below:

<SCRIPT LANGUAGE='javascript' SRC='BlogspotIPblocker.php' TYPE='text/javascript'>
</SCRIPT>


with that URL whereupon the above become:

<SCRIPT LANGUAGE='javascript' SRC='http://bloggerfordummies.110mb.com/BlogspotIPblocker.php' TYPE='text/javascript'>
</SCRIPT>


and was copy-pasted to just before </head> in the template. The portion in the template just before </head> in the template thus become

<SCRIPT LANGUAGE='javascript' SRC='http://bloggerfordummies.110mb.com/BlogspotIPblocker.php' TYPE='text/javascript'>
</SCRIPT>
</head>

2 comments:

Deepak said...

Hi Peter,

you have done every thing correctly, but your hosted file URL is not accessible (http://bloggerfordummies.110mb.com/BlogspotIPblocker.php) hence the whole script is not working. Just upload your (.php) file correctly. Please not that if you access the uploaded file from the same IP address which you have blocked, you will see the following texts only.

top.location = "error.html";

Because you have blocked the same IP Address. Please upload your file again, If 110mb.com is not working you can also try another host which support .php files to upload your script file. I hope this suggestion will solve your problem.

Deepak said...

Hi Peter,

you have done every thing correctly, but your hosted file URL is not accessible (http://bloggerfordummies.110mb.com/BlogspotIPblocker.php) hence the whole script is not working. Just upload your (.php) file correctly. Please not that if you access the uploaded file from the same IP address which you have blocked, you will see the following texts only.

top.location = "error.html";

Because you have blocked the same IP Address. Please upload your file again, If 110mb.com is not working you can also try another host which support .php files to upload your script file. I hope this suggestion will solve your problem.