Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: PHP Ban IP Addresses from your site Tutorial

How to make an easy an maintainable IP blocking PHP system

Tutorial Details:

PHP/MySQL and Visual Basic

The basic scenario is this. There is a really annoying person on the forum that threatens to hack and take down your site (yadda yadda yadda), so for some reason.. for this, we want to ban him from the site.

We are going to have a MySQL table from which you will enter the IP Address of the banee. Then there will be a place to enter a reason.

So lets create the table..
Code
CREATE TABLE `banned` (
`ip_addr` varchar(15) NOT NULL default '',
`reason` varchar(255) NOT NULL default ''
)
Then simply log into phpMyAdmin or something, so that you can add your records easily, and enter the ip address of your banee, and a reason to show him/her when they get the bump.
Now at the top of every page you want them banned from, throw this code.
PHP Code
//remember to put your MySQL information here, check out the php tutorial section if you dont know how to do this.
$sql = "SELECT `reason` FROM `banned` WHERE `ip_addr` = '" . $_SERVER [ 'REMOTE_ADDR' ]. "'" ;
$dosql = mysql_connect ( $sql , $connect );
if( mysql_num_rows ( $dosql ) == 1 )
{
//the user is banned, lets show him the reason.,
$reason = mysql_fetch_assoc ( $dosql );
echo "You have been banned, loser.

" ;
echo "Reason: " . $reason ;
exit;
}
?>
The code is pretty easy. The exit(); makes the php script stop completely and not output anything else, or carry out any other operation on that page. It essentially tells the php script that there is nothing left to do, so it quits out.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
PHP Ban IP Addresses from your site Tutorial

View Tutorial:
PHP Ban IP Addresses from your site Tutorial

Related Tutorials:

Results of first-ever JVM server benchmark revealed - JavaWorld - December 1997
Results of first-ever JVM server benchmark revealed - JavaWorld - December 1997
 
Multicast the chatwaves - JavaWorld October 1999
Multicast the chatwaves - JavaWorld October 1999
 
JMS: An infrastructure for XML-based business-to-business communication - JavaWorld February 2000
JMS: An infrastructure for XML-based business-to-business communication - JavaWorld February 2000
 
Apple announces Java 2 plans at MacWorld
Apple announces Java 2 plans at MacWorld
 
Sockets programming in Java: A tutorial - JavaWorld December 1996
Sockets programming in Java: A tutorial - JavaWorld December 1996
 
J2EE clustering, Part 2 - JavaWorld August 2001
J2EE clustering, Part 2 - JavaWorld August 2001
 
Create email-based apps with JAMES
Create email-based apps with JAMES
 
Jini-like discovery for RMI
Jini-like discovery for RMI
 
Once again, only introduction
Once again, only introduction
 
Excellent tutorial on Struts and Tiles
Excellent tutorial on Struts and Tiles This tutorial assumes knowledge of Java, JDBC, Servlets, J2EE (with regards to Web applications) and JSP Struts in a holistic manner, minus the beads and crystals. The Tiles framework makes creating reusable pages
 
JSP Tutorial
This Tutorial is for beginners in the Java Server Pages Technology
 
Developing Simple Struts Tiles Application
In this tutorial I will show you how to develop simple Struts Tiles Application. You will learn how to setup the Struts Tiles and create example page with it.
 
Welcome to Java Developers paradise!
Welcome to Java Developers paradise! T his site contains many quality Java, JSP, RMI, MySQL downloads, tutorials, source codes and links to other java resources. We have large number of links to the tutorials on java which will help you learn java
 
Accessing Database from servlets through JDBC!
Accessing Database from servlets through JDBC! Accessing Access Database From Servlet T his article shows you how to access database from servlets. Here I am assuming that you are using win95/98/2000 and running Java Web Server. For the sake of
 
Building Search Engine Applications Using Servlets !
Building Search Engine Applications Using Servlets ! Building Search Engine Applications Using Servlets Please visit http://www.webappcabaret.com/javadevelopers/search to see running copy of our search engine. Introduction This tutorial takes
 
Struts Guide
Struts Guide Struts Guide This tutorial is extensive guide to the Struts Framework. In this tutorial you will learn how to develop robust application using Jakarta Struts Framework. This tutorial assumes that the reader is familiar with the web
 
WAP Toolkits Motorola - Mobile ADK 1.1 Nokia - WAP Toolkit
WAP Toolkits Motorola - Mobile ADK 1.1 Nokia - WAP Toolkit Tutorial WAP Toolkits T o develop any WAP application you have to download software essential for development. Although you can write and test your codes through our site for learning
 
Web Hosting Guide. What is Web Hosting Plan?
Web Hosting Guide. What is Web Hosting Plan? What is Web Hosting Plan? Web hosting plan is the different plans provided by Hosting Companies for hosting your web site. Web hosting plans include the storage limit, bandwidth, access to server
 
What is Web Hosting
What is Web Hosting What is Web Hosting? What is Web Hosting? If you have a company and want web presence than you need a website. With the website any one from the world must be able to view your pages, images etc. Website is actually a
 
Integrating Java Open Single Sign-On in Pluto
This article shows how to integrate Java Open Single Sign-On in Apache\'s Pluto portlet container.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.