Google Community Chat
 
PHP IP Ban

You're visiting Google Community as a guest.
In order to post, you'll need to register and log in.



(If you were registered and logged in, these advertisements wouldn't be here)
Post new topic   Reply to topic    Google Community Forum Index // Web Design, Coding & Programming Forum
   
Author Message
puccavn
Noogle
Noogle


Joined: 12 Apr 2005

1021.15 GC$

Items

PostPosted: Thu May 05, 2005 11:51 pm    Post subject: PHP IP Ban Reply with quote
1. What it does

IP banning someone from your site will effectivly stop all access they have to your website. Make sure you ban wisely Razz

2. The Code

The code is fairly simple, we will set the $banned variable using an array. It is here were we will enter IP address we wish to ban. Then, using the global variable $REMOTE_ADDR to give us the user's IP address, we can check if it is in the $banned array. If not, we let them carry on. If it is found in the $banned array, using the die() fuction, we can remove all access to the site from that IP.

<?php
$banned = array("1.1.1.1", "2.2.2.2", "3.3.3.3");
(in_array("$REMOTE_ADDR", $banned_addresses)) {
die("You have been banned from this site");
}
?>

3. Adding the ban filter

Save the above into ban.php or similar, then include it on all the pages you want it to be effective on, using the include() fuction.

Please contact us if you enjoyed this tutorial, or find any typos, etc
Back to top
View user's profile Send private message
Sponsored Links
Posted: 5 Dec 2008 10:18 am    Post subject: Advertisements
Back to top
Post new topic   Reply to topic    Google Community Forum Index // Web Design, Coding & Programming Forum All times are GMT - 8 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Host your free forums with Invision Plus.net forum web hosting with your own subdomain.

alexisBlue v1.2 // Theme Created By: Andrew Charron // Icons in Part By: Travis Carden

© 2005-2006 Google Community

Powered by phpBB

Privacy Policy | Contact Us

Powered by Google Search blog

This website is not affiliated in any way with Google, Inc.
Google™ is a registered trademark of Google, Inc.