Can any1 tell me the script or what eva to block an ip cos the ones i used before didnt work :S
Printable View
Can any1 tell me the script or what eva to block an ip cos the ones i used before didnt work :S
On cpanel that I use theres a section to Ban IPs I think its wat most people use
kk wots it called
It's easy to do :)
PHP Code:<?php
if ($_SERVER['REMOTE_ADDR'] == "THE IP YOU WANT TO BAN") {
die("You have been IP banned.");
}
?>
If you want to ban multiple IPs I reccommend to use an array not to use elseif's :P
If you have multiple:
PHP Code:<?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.");
}
}
?>
U Can use a Redirect One -OR PHPHTML Code:<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>
<SPAN style="COLOR: #000000">HTML Code:<?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
}
?>
NEVER use javascript for something like an IP Blocker ;)
PHP ftw.
This one is quite good (PHP):
Code:<?
$ip = $_SERVER['REMOTE_ADDR'];
if($ip == "IPHERE")
{
echo "<h1>Forbidden Access</h1>";
}
?>