FORUM HOME | WHUK BLOG   
WEB HOSTING UK AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM
PHP LINUX SHARED HOSTING WINDOWS ASP.NET HOSTING PACKAGES
ECOMMERCE HOSTING ASP MSSQL MS ACCESS ODBC FRONTPAGE HOSTING
CPANEL WHM FANTASTICO RESELLER DEDICATED SERVER WEB HOSTING
CHEAP PLESK CPANEL HTML MYSQL BEST UK VPS HOSTING COMPANY
CHEAP RELIABLE UK HOSTING PROVIDER SINCE 2001
MANAGED WEB HOSTING SERVICE
AFFORDABLE WEBSITE HOSTING SERVICES IN UNITED KINGDOM

Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum » Web Hosting and Domains » FAQ's / Tutorials.

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 10-09-07, 04:32 PM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default Small IP Blocking script

Code:
<?php  
$blockip = array(
'123.123.123.123'=> 'Block reason1',
'456.456.456.456'=> 'block reason2'
);

foreach($blockip as $key=>$val)
{if ($_SERVER['REMOTE_ADDR'] == $key) 
 {   
 die("You Have Been Banned because $val");
 }
}
?>
Just include this code on the start of every page of your site and set the different ban IPs along with different banning reason.
This just the basic concept of banning IP by php.
Reply With Quote

  #2 (permalink)  
Old 11-09-07, 11:04 AM
Sales Team
 
Join Date: Sep 2006
Posts: 1,628
Send a message via MSN to Harry Send a message via Skype™ to Harry
Default

Thanks for sharing such useful script
I think /etc/hosts.deny would be the better option for blocking IP's or range of IP's

One good thing about this PHP script is that we can display message for all banned IP's
Reply With Quote

  #3 (permalink)  
Old 11-09-07, 11:31 AM
paul's Avatar
Senior Member
 
Join Date: Apr 2006
Location: Norway
Posts: 1,788
Default

I like this feature- You Have Been Banned because... , thanks SBh for the code.
__________________

Reply With Quote

  #4 (permalink)  
Old 11-09-07, 11:39 AM
Administrator
 
Join Date: Mar 2006
Posts: 1,934
Default

Quote:
Originally Posted by harry View Post
Thanks for sharing such useful script
I think /etc/hosts.deny would be the better option for blocking IP's or range of IP's

One good thing about this PHP script is that we can display message for all banned IP's
/etc/hosts.deny is good to block IPs throughout the server. Shared hosting customers cannot request us to block IPs through /etc/hosts.deny so such php script looks like a good solution.
__________________
Web Hosting UK - ASP MSSQL Hosting - cPanel Linux Hosting
AIM : webredback || msn : andrew @ webhosting.uk.com
Toll Free : 0808 262 0855
Reply With Quote

  #5 (permalink)  
Old 11-09-07, 12:08 PM
Sales Team
 
Join Date: Sep 2006
Posts: 1,628
Send a message via MSN to Harry Send a message via Skype™ to Harry
Default

Thanks Admin for your helpful reply
That mean this script is very useful for all webmaster who are using shared hosting.
Reply With Quote

  #6 (permalink)  
Old 11-09-07, 12:17 PM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default

With some more modification in this script you can also discriminate among visitors such as search-bots, and can behave in a different way.
Reply With Quote

  #7 (permalink)  
Old 06-12-07, 06:36 PM
Member
 
Join Date: Dec 2007
Posts: 50
Send a message via MSN to Jamesking56
Default

cool
Reply With Quote

  #8 (permalink)  
Old 13-01-08, 09:59 PM
Senior Member
 
Join Date: Dec 2006
Posts: 684
Send a message via MSN to karimali831
Default

Quote:
Originally Posted by SBh View Post
Code:
<?php  
$blockip = array(
'123.123.123.123'=> 'Block reason1',
'456.456.456.456'=> 'block reason2'
);

foreach($blockip as $key=>$val)
{if ($_SERVER['REMOTE_ADDR'] == $key) 
 {   
 die("You Have Been Banned because $val");
 }
}
?>
Just include this code on the start of every page of your site and set the different ban IPs along with different banning reason.
This just the basic concept of banning IP by php.
Thanks alot for this, this will come in handy some day
Reply With Quote

  #9 (permalink)  
Old 28-01-09, 09:52 PM
Junior Member
 
Join Date: Jan 2009
Location: root@127.0.0.1 [~]# cd /etc/pwd
Posts: 12
Send a message via MSN to XXxxImmortalxxXX
Default

Good job but u may ban there ip but whos to say they wont use a proxy next?

what someone needs to make is a proxy detection automatic ban ip thing

ive tried tons of times to make this and i have still failed but hey maybe someone else out there has done it
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT. The time now is 01:19 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Copyright 2001-2010 Web Hosting UK. All rights reserved.
Web Hosting UK Forum





Site Map

Shared Cloud
Shared Cloud From £1

Affiliate Program
Earn up to £300 Per Sale

Dedicated Servers
Dedicated Server Hosting

Cloud Hosting
Cloud Server Hosting

Load Balanced Server
Load Balancing Server

VPS Hosting
Linux VPS Hosting

Windows VPS
Windows 2003 VPS

Zimbra Hosting
Zimbra Email Hosting

cPanel Hosting
Shared Linux Hosting

Windows Hosting
Shared Windows Hosting

Coldfusion Hosting
Windows Coldfusion Hosting

cPanel Reseller Hosting
Shared Windows Hosting

Windows Reseller
Windows Reseller Hosting

Email Web Hosting
Email Hosting

Semi-Dedicated Server
Semi-Dedicated Hosting

Remote Backup Plans
Offsite Backup Service


cpanel hosting
Knowledgebase Articles

Pre-Sales Question
Web Hosting FAQ's

Dedicated Hosting
Dedicated Server FAQ's

Virtual Private Servers
VPS Hosting

PHP MySQL Hosting
cPanel Hosting

Windows Hosting
ASP MSSQL Hosting

Domain Name
Domain registration FAQ's

CMS Hosting
CMS Hosting FAQ's

Payment Gateways
Payment FAQ's


Support Tutorials

cPanel Tutorials
cPanel Flash Tutorials

Wordpress Tutorials
Wordpress Flash Tutorials

Plesk Tutorials
Plesk Flash Tutorials

PhpMyadmin Tutorials
PhpMyadmin Flash Tutorials

Drupal Tutorials
Drupal Flash Tutorials

Mambo Tutorials
Mambo Flash Tutorials

Joomla Tutorials
Joomla Flash Tutorials

More Hosting Tutorials