Friday, March 21, 2008

PHP code to block IP to view your page

Suppose your are in a situation that you don't want to view your pages from specific IP address. You can either block them or can redirect to another default page saying "your are not allowed to view the page", or "your blocked :-p". Check the below PHP code.

## Make an array of IP address that you want to block.
$blocked_ip = array("","");

## This is the IP address from where request came to you
$request_ip = $_SERVER["HTTP_CLIENT_IP"];

## If the requested IP address exist at blocked IP list
if(array_search($request_ip, $blocked_ip)){
   ## You can stop the script here.

but my suggestion is to redirect to another page instead of die().

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:");

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...