

 Php Country Detector by IP (RESTRICT VISITS) - Version 3.4 for Text File databases - advanced redirection
	Copyright (C) 2003 Ionita Dragos Alexandru

This program is free software; you can redistribute it and/or modify it under the terms of 
the GNU General Public License as published by the Free Software Foundation; either version 
2 of the License, or any later version. 

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
See the GNU General Public License for more details.

CONTACT:
	http://rv.web-heaven.com
	rv@web-heaven.com

DOWNLOAD UPDATES AND REQUEST IP DATABASES FOR EACH COUNTRY FROM :
	http://rv.web-heaven.com

WHAT DOES IT DO?

- A script which reads a set of text files, in a certain order, containing IP`s and decides if the visitor`s IP is there. 
- In the advanced redirection version, each country (or IP database) has a redirection link associated with it. If the user`s IP is in an IP database it is redirected to the redirection link associated with it, or if this one is blank, to the default redirection link. If this default redirection link is blank too, the page is loaded. If the user is in no database, he is redirected to the default 'not in database' link or if this one is blank, the page is loaded

- It features an exception list, where you can place your trusted IPs.

- You can also set the order in which the country databases are scanned and a redirection link for each country.

- The plain text databases supported are: "Plain text - one file with IP numbers and country code", "Plain text - one file/country with IP numbers", "Plain text - one file with IP addresses and country code" and "Plain text - one file/country with IP addresses"

- To deny/grant/redirect traffic from a certain country you need the file containing all IP`s assigned to that country which you can buy at http://rv.web-heaven.com/buy.php

REQUIREMENTS:
	Apache web server with PHP minimum version 4.1.x

FILES:
	ip/ip.php - script file
	ip/country_order.txt - a text file to help you improuve performance. it sets the order in with the files will be scanned. use '#' to comment out countries. Add at the end of the line the link where user from that country should be redirected, or leave blank to use the default reject link
	ip_databases/[database type]/[_]restrict-visits-XX.php - ip database files (the default files are IP addresses from a few countries).
	ip/.htaccess - to deny acces to ip folder, to avoid abuse.
	ip/exceptions.php - guess what? an exception list with clasic IP addresses or IP ranges
	exemple.php - a sample file

	[database type] could be:
		tc=one plain text file / country with IP addresses (192.168.0.1)
		tcs=one plain text file with IP addresses and country code
		to=one plain text file / country with IP numbers (3243232321)
		tos=one plain text file with IP numbers and country code

OPTIMIZED IP`s (IP numbers):
	In a plain text database with IP numbers, lines are like 3268209248-3268209250; In HEXA it is C2CCEA60-C2CCEA62. Let`s take groups of 2 : C2.CC.EA.60-C2.CC.EA.62 and make each group DECIMAL again: 194.204.234.96-194.204.234.98.

INSTALL:
 Edit ip.php and modify to reflect your filter and your actions.
 Edit country_order.txt to set the order in wich the text databases are scanned. Use # to coment out countries and ' - ' (space,minus,space) to separate Country sufix, Country name, and redirection link.
 Add the next line at the beginning of EVERY PAGE YOU NEED TO PROTECT:

	<?PHP $ip_path="ip/"; include($ip_path."ip.php"); ?>

		or (if ip directory is a level up)

	<?PHP $ip_path="../ip/"; include($ip_path."ip.php"); ?> 

 Be carefull! The script is setting cookies so it`s a MUST that no character (not even space or newline) should be in front of <?PHP $ip_path=".....

TESTING AND DEBUG-ING
 To test and debug you need to set in ip.php the constant _DEBUG_MODE to 1: define("_DEBUG_MODE","1"); Then close all browser windows to clear any cookies sent by the script, and in one of the databases or in the exception list, enter your IP (127.0.0.1 = 2130706433)

 Now open a new browser window and go to http://[your server]/[your site]/exemple.php

 Warning: if you set debug mode off and you want to test the script, you have to close all browser windows to make sure cookies are erased before making changes to the script and to the databases, otherwise, the first taken action will be repeated when the page is reloaded, no matter the changes in the databases. Also if the redirection link do not exist, Internet Explorer will print that your restricted page do not exist, not that the redirection link do not exist.

