View Full Version : IP Block
DJ-Whoeva
19-04-2007, 07:17 PM
Can any1 tell me the script or what eva to block an ip cos the ones i used before didnt work :S
PenguinFluid
19-04-2007, 07:20 PM
On cpanel that I use theres a section to Ban IPs I think its wat most people use
DJ-Whoeva
19-04-2007, 07:20 PM
kk wots it called
timROGERS
19-04-2007, 07:24 PM
It's easy to do :)
<?php
if ($_SERVER['REMOTE_ADDR'] == "THE IP YOU WANT TO BAN") {
die("You have been IP banned.");
}
?>
Invent
19-04-2007, 07:29 PM
If you want to ban multiple IPs I reccommend to use an array not to use elseif's :P
timROGERS
19-04-2007, 07:36 PM
If you have multiple:
<?php
$array = array("first ip", "second ip", "third ip", "etc");
foreach ($array as $ip) {
if ($_SERVER['REMOTE_ADDR'] == $ip) {
die("You've been IP banned.");
}
}
?>
phpme
19-04-2007, 10:32 PM
U Can use a Redirect One -
<script language="JavaScript" type= "text/javascript" >
// Script for visitor banning by IP address.
//
// May be placed in the head or in the body segment of an html page.
// Always use Notepad or another plain text editor, not a WYSIWYG editor unless you work in code view mode.
// Since this script uses SSI, the web page may have to be named with the extension shtml instead of html or it will not work,
// unless the server allows SSI to be used in ordinary html pages.
// Please not that the nature of SSI makes it impossible to turn this into a javascipt source, you must include everything.
// Put in the address to which you want to redirect if the user is banned
// it may be a page on your site or the url of another web site that exists
// the url given below is just an example, as good as any
var banned_ip_page = "http://www.google.com"; // This is the page to direct to if the ip is banned
// get the visitor's IP address
var visitor_ip = ''; // This is the visitor's IP address as returned by the server
// User defined test - add as many groups as you need for all the banned ips;
// Make sure you modify these example ip addresses and do not lock yourself out.
// The || (vertical bars or pipe lines) mean "or" and the == is used to test equality
// Each individual test is enclosed in parentheses
// The entire set of tests is enclosed in parentheses
if ( // opening parenthesis for the entire test
// You may change the tests from here
(visitor_ip == "000.000.000.000" )
|| (visitor_ip == "111.111.111.111" )
|| (visitor_ip == "222.222.222.222" )
// until here
) // closing parenthesis for the entire test
{ alert("Sorry, your IP has been banned from this site");
document.location = banned_ip_page; }
</script>
OR PHP
<SPAN style="COLOR: #000000">
<?php
$banned[0]="ip address 1";
$banned[1]="ip address 2";
$banned[2]="ip address 3";
if (in_array($_SERVER['REMOTE_ADDR'],$banned))
{
echo "You have been banned from this site!!!";
} else {
// Stuff to display if user is accepted
}
?>
Invent
19-04-2007, 10:34 PM
NEVER use javascript for something like an IP Blocker ;)
PHP ftw.
Jazza
19-04-2007, 10:59 PM
This one is quite good (PHP):
<?
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == "IPHERE")
{
echo "<h1>Forbidden Access</h1>";
}
?>
timROGERS
20-04-2007, 06:33 AM
This one is quite good (PHP):
<?
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == "IPHERE")
{
echo "<h1>Forbidden Access</h1>";
}
?>
You need to use die, because with that the page will keep displaying itself :P So you won't be banned :P
Yaesu
20-04-2007, 08:59 AM
cpanel > ip deny list then tap in the ip u wanna ban then hey presto. Lol.
Recursion
20-04-2007, 10:09 AM
Yeh, just use the cPanel one, then it will do it for the hole hosting account (i.e. they cant access ANY files on your shared hosting :))
Sygon..
20-04-2007, 02:56 PM
On cpanel that I use theres a section to Ban IPs I think its wat most people use
Thats .htaccess banning.
DJ-Whoeva
20-04-2007, 04:36 PM
Thanks every1 i finally no how 2 do it using Cpanel ty :D lol
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.