Forum Moderators: coopster

Message Too Old, No Replies

Ban IP from opening HTML page with PHP

Ban IP from opening HTML page with PHP (and one line of java)

         

kikiat

11:22 am on Jun 27, 2007 (gmt 0)

10+ Year Member



you may ban IP from accessing your HTML pages by using the following PHP script:

___________________________________________________________

***************
ban.php (replace €€€€€€ by the redirection URL, for example a void page an image or anything else)

<?php

$filename = "ban.txt";
$handle = fopen($filename, "r");
$string = fread($handle, filesize($filename));
fclose($handle);

$sArr = explode("\n",$string);

//get user IP address
$userip = $_SERVER['REMOTE_ADDR'];

//check for banned IP address
if (in_array($userip, $sArr)) {
echo "<script type=\"text/javascript\" language=\"javascript\">";
echo "window.open(\"€€€€€€\",\"_top\");";
echo "</script>";
}
?>

***************
then add to your html page the following code between <body> and </body>:

<iframe scrolling="no" name="ban_Invisible_frame" src="ban.php" width="0" height="0" frameborder="0" border="0" ></iframe>

*************
Then create a txt file 'ban.txt'.
And put one IP per line.

___________________________________________________________

Quite useful to ban some annoying visitors. ;-)

phparion

11:43 am on Jun 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



GeoRedirect with Apache's mod_geoip is a lot easier than what you have suggested. As the IP will be banned only once in one place for complete website and your method will become a pain in neck for even 30 html pages.

even if you do not have mod_geoip support then do it with htaccess rather putting frames in your pages.

and btw it should not be JAVA but JAVASCRIPT in your post's title

[edited by: phparion at 11:46 am (utc) on June 27, 2007]

Habtom

11:46 am on Jun 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



do it with htaccess rather putting frames in your pages.

The idea of having frames on my site disturbs me.

kikiat, your idea is not bad, but there are lots of easier ways of doing that.

Hab

kikiat

4:13 am on Jun 28, 2007 (gmt 0)

10+ Year Member



Actually i had to develop this method because I've got a website hosted by a really low-cost host.

So low-cost that I don't have any control over the server side (no right to change CHMOD 644, no htaccess available, no URL rewritting..., well just the minimum + PHP). :-(

That's the only way I could find to put a banning system considering the limitations of my host.

Do you have other methods for a limited server-side control and without htaccess?

phparion --> Javascript indeed ;-p

vincevincevince

4:17 am on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd recommend using PHP pages straight off, and then issuing die(); if the IP is banned. Don't use .html if you can't have them parsed by PHP.