|| Target Country by IP Address
Target Country by IP Addressv2.01 - advanced redirection
1. General description
3. Testing and debuging PHP Target Country by IP Address
4. Useful hints
1. General description
Target Country by IP Address is a complete web-based software that provides webmasters with the ability to redirect/restrict traffic based on the visitor's country of origin.This allows webmasters to promote their services and products in different countries where they have specific distribution and service capabilities in different countries.
This is not a simple
cut-and-paste script. Yet installation procedure is rather short. Download the archive file containing the script and unpack it. This will contain:
- cr/.htaccess - Apache restriction file, to deny access to cr/ folder, to avoid abuse
- cr/anp_ips.dat - a free IP2Country database - type: Plain text full with IP numbers
- cr/cr_free.sql - Sql Dump of the same free database
- cr/exceptions_ips.dat - A list of IPs who will be excuded from the redirection.
It can only have IP addresses (220.127.116.11) or IP address ranges; Edit this
file to add exceptions ip address; Exemple:
- cr/blocked_ips.dat - A list of IPs who will be excuded from the redirection.
It can only have IP addresses (192.168.0.1) or IP address ranges; Edit this
file to add blocked ip address; Exemple:
- cr/cr.php - main script file, Edit this file for configuration
- cr/anp_****.php - aditional functions
- cr/Countries.php - Get Country information files
- cr/cur_re_rules.php - default redirection rules file.
- cr/_re_rules.php - redirection rules template file.
- cr/Countries.* - Country information files
- cr/flags/* - GIF country flags
Install step by step:
Edit cr/cr.php and modify it as described there.
Add the next line at the beginning of EVERY PAGE YOU NEED TO REDIRECT VISITORS:
<?PHP $anp_path="cr/"; include($anp_path."cr.php");
or (if cr/ directory is a level up)
<?PHP $anp_path="../cr/"; include($anp_path."cr.php");?>
If you use MySql, load cr/cr_free.sql into your mysql server:
mysql -u [username] -p
mysql>use [your database]
mysql>source [path to/]anp_ip2country.sql
If you want a different set of redirection rules in other pages of your website,you
could use the same databases and the same script.
All you can make a copy of _re_rules.php -> new_re_rules.php,edit new_re_rules.php,just
change the REDIRECTION RULES. Then include it in your files with:
<?php $re_rules = "new_re_rules.php"; $anp_path="cr/";
3.Testing and debuging
Target Country by IP Address
- To test and debug you need to set in cr/cr.php the constant _DEBUG_MODE
1: define("_DEBUG_MODE","1") then poin your browser
- Now play with the configuration, modify
- When you are satisfied, set _DEBUG_MODE to 2, In order
to test how cookies
/ session vars are saved.
- When it`s ok set _DEBUG_MODE to 0.
4. Useful hints
- If you want to use Target Country by IP Address just to detect the country
of your visitor and to get the country details in an array, edit cr/cur_re_rules.php
comment out all REDIRECTION RULES and make blank the default redirect and
reject links ( =""; ).
Then edit demo.php to see how you can use the country details of your visitor.
Add the next line:
<?php include($anp_path."countries.php"); $anp_cinfo=get_cinfo($anp_country_code);?>
This fields can be used in your scripts:
$anp_cinfo["region"] $anp_cinfo["capital"] $anp_cinfo["currency"] $rv_cinfo["flag_path"] ;
The flag image can be generated like this: <img src="<?php echo $rv_cinfo["flag_path"]; ?>" alt=""border="0">
- Blocks certain IP address's from your site and redirects the user to a
You have to set : $bCheckBlocked = true; $anp_blocked_reject_link= an invalid url.
Then Edit blocked_ips.dat,add the IP addresses or IP address ranges you want to block. Exemple:
- If you want to use Target Country by IP Address
to safely reject all visitors from country XX and YY and to accept all
the other visitors.
you must set :
edit the Redirection Rules file(cur_re_rules.dat), for country XX uncomment
the line and place an invalid url for it (XX=error.php) . Do the same for
- If you need to display language specific pages for Italy and German:
edit the Redirection Rules file(cur_re_rules.php), for country IT uncomment
as redirection rule set IT=yourpage_en.htm; Do the same for DE;
if you want to be 97% sure that the IP -> Country conversion
is realistic, you have to use the best database on the market, database provided
by us at ip2country