Country Block PHP Script for free

Country Block PHP Script for free is a simple php script bassed on geo ip location script very easy to install in any php server ,and this script can be usefull in many way ,example if you want redirect the blocked visitor from your page to an other page you can see this example from this link :https://s-educatetools.com/PHP%20Country%20Block%20Script/

you can see from this example all country are banned and only people from algeria are allowed to see this page .

PHP blocking website access by country Code

<?php
include(“geoiploc.php”); // Must include this
$ip = $_SERVER[“REMOTE_ADDR”];
$countrydetected = getCountryFromIP($ip, “code”);

if (($countrydetected) == ‘DZ’) {

echo “Your Country Name is: “;

echo getCountryFromIP($ip, ” NamE “);

echo “<br />\n”;

echo getCountryFromIP($ip, ” NamE “);

echo ‘ IS DETECTED As Your Country So you can use anything and show anything here’;

header(‘refresh: 10; url=https://s-educatetools.com’); // redirect the user after 10 seconds

#exit; // note that exit is not required, HTML can be displayed.

} else {

echo”Sorry “;

echo getCountryFromIP($ip, ” NamE “);

echo ” Country is Not Allowed To see this page<br />\n”;
}
?>

How to Block a country by using the country code name

this code is very easy to edit you just have to edit the country code name and add a redirect link

in this example you can see u used FR  so anyone from french will be blocked but all others visitors from a different country will be redirected to the link https://s-educatetools.com .

<?php

include(“geoiploc.php”); // Must include this

$ip = $_SERVER[“REMOTE_ADDR”];

$countrydetected = getCountryFromIP($ip, “code”);

if (($countrydetected) == ‘FR’) {

echo “Your Country Name is: “;

echo getCountryFromIP($ip, ” NamE “);

echo “<br />\n”;

echo getCountryFromIP($ip, ” NamE “);

echo”Sorry “;
echo getCountryFromIP($ip, ” NamE “);
echo ” Country is Not Allowed To see this page<br />\n”;

} else {

header(‘refresh: 10; url=https://s-educatetools.com’); // redirect the user after 10 seconds
#exit; // note that exit is not required, HTML can be displayed.

}
?>

List of all countries with their 2 digit codes

A

Afghanistan AF
Åland Islands AX
Albania AL
Algeria DZ
American Samoa AS
Andorra AD
Angola AO
Anguilla AI
Antarctica AQ
Antigua and Barbuda AG
Argentina AR
Armenia AM
Aruba AW
Australia AU
Austria AT
Azerbaijan AZ

B

Bahrain BH
Bahamas BS
Bangladesh BD
Barbados BB
Belarus BY
Belgium BE
Belize BZ
Benin BJ
Bermuda BM
Bhutan BT
Bolivia, Plurinational State of BO
Bonaire, Sint Eustatius and Saba BQ
Bosnia and Herzegovina BA
Botswana BW
Bouvet Island BV
Brazil BR
British Indian Ocean Territory IO
Brunei Darussalam BN
Bulgaria BG
Burkina Faso BF
Burundi BI

C

Cambodia KH
Cameroon CM
Canada CA
Cape Verde CV
Cayman Islands KY
Central African Republic CF
Chad TD
Chile CL
China CN
Christmas Island CX
Cocos (Keeling) Islands CC
Colombia CO
Comoros KM
Congo CG
Congo, the Democratic Republic of the CD
Cook Islands CK
Costa Rica CR
Côte d’Ivoire CI
Croatia HR
Cuba CU
Curaçao CW
Cyprus CY
Czech Republic CZ

D

Denmark DK
Djibouti DJ
Dominica DM
Dominican Republic DO

E

Ecuador EC
Egypt EG
El Salvador SV
Equatorial Guinea GQ
Eritrea ER
Estonia EE
Ethiopia ET

F

Falkland Islands (Malvinas) FK
Faroe Islands FO
Fiji FJ
Finland FI
France FR
French Guiana GF
Fr Polynesia PF
Fr Territories TF

G

Gabon GA
Gambia GM
Georgia GE
Germany DE
Ghana GH
Gibraltar GI
Greece GR
Greenland GL
Grenada GD
Guadeloupe GP
Guam GU
Guatemala GT
Guernsey GG
Guinea GN
Guinea-Bissau GW
Guyana GY

H

Haiti HT
Heard Island and McDonald Islands HM
Holy See (Vatican City State) VA
Honduras HN
Hong Kong HK
Hungary HU

I

Iceland IS
India IN
Indonesia ID
Iran, Islamic Republic of IR
Iraq IQ
Ireland IE
Isle of Man IM
Israel IL
Italy IT

J

Jamaica JM
Japan JP
Jersey JE
Jordan JO

K

Kazakhstan KZ
Kenya KE
Kiribati KI
Korea, Democratic People’s Republic of KP
Korea, Republic of KR
Kuwait KW
Kyrgyzstan KG

L

Lao People’s Democratic Republic LA
Latvia LV
Lebanon LB
Lesotho LS
Liberia LR
Libya LY
Liechtenstein LI
Lithuania LT
Luxembourg LU

M

Macao MO
Macedonia, the Former Yugoslav Republic of MK
Madagascar MG
Malawi MW
Malaysia MY
Maldives MV
Mali ML
Malta MT
Marshall Islands MH
Martinique MQ
Mauritania MR
Mauritius MU
Mayotte YT
Mexico MX
Micronesia, Federated States of FM
Moldova, Republic of MD
Monaco MC
Mongolia MN
Montenegro ME
Montserrat MS
Morocco MA
Mozambique MZ
Myanmar MM

N

Namibia NA
Nauru NR
Nepal NP
Netherlands NL
New Caledonia NC
New Zealand NZ
Nicaragua NI
Niger NE
Nigeria NG
Niue NU
Norfolk Island NF
Northern Mariana Islands MP
Norway NO

O

Oman OM

P

Pakistan PK
Palau PW
Palestine, State of PS
Panama PA
Papua New Guinea PG
Paraguay PY
Peru PE
Philippines PH
Pitcairn PN
Poland PL
Portugal PT
Puerto Rico PR

Q

Qatar QA

R

Réunion RE
Romania RO
Russian Federation RU
Rwanda RW

S

Saint Barthélemy BL
S Helena, Ascension and Tristan da Cunha SH
-Saint Kitts and Nevis KN
-Saint Lucia LC
-S Martin (French part) MF
Saint Pierre and Miquelon PM
S Vincent and the Grenadines VC
Samoa WS
San Marino SM
Sao Tome and Principe ST
Saudi Arabia SA
Senegal SN
Serbia RS
Seychelles SC
Sierra Leone SL
Singapore SG
Sint Maarten (Dutch part) SX
Slovakia SK
Slovenia SI
Solomon Islands SB
Somalia SO
South Africa ZA
South Georgia and the South Sandwich Islands GS
Sth Sudan SS
Spain ES
Sri Lanka LK
Sudan SD
Suriname SR
Svalbard and Jan Mayen SJ
Swaziland SZ
Sweden SE
Switzerland CH
Syrian Arab Republic SY

T

Taiwan, Province of China TW
Tajikistan TJ
Tanzania, United Republic of TZ
Thailand TH
Timor-Leste TL
Togo TG
Tokelau TK
Tonga TO
Trinidad and Tobago TT
Tunisia TN
Turkey TR
Turkmenistan TM
Turks and Caicos Islands TC
Tuvalu TV

U

Uganda UG
Ukraine UA
United Arab Emirates AE
Un Kingdom GB
United States US
Un States Minor Outlying Islands UM
Uruguay UY
Uzbekistan UZ

V

Vanuatu VU
Venezuela, Bolivarian Republic of VE
Viet Nam VN
Virgin Islands, British VG
Virgin Islands, U.S. VI
Wallis and Futuna WF
Western Sahara EH

Y

Yemen YE

Z

Zambia ZM
Zimbabwe ZW

You can download this PHP COUNTRY BLOCK script here :

Download PHP COUNTRY BLOCK.rar

if you need anything leave a comment and I will reply within 24 hours.