I want to block people from some country to register on my site but i want to them to be able to see the index file. I have a code for block them trough the .htaccess file on the index but how do i write the code for the register.php file?
I dont know how you do it via .htaccess but I would do it with a query like this <?php error_reporting(0); $ip = $_SERVER['REMOTE_ADDR']; $file = file_get_contents("http://www.melissadata.com/lookups/iplocation.asp?ipaddress=" . $ip); preg_match('^<tr><td align="right">Country</td><td><b>([A-Z]+)</b></td></tr>^',$file , $country); $country = $country[1]; if($country == "COUNRY NAME HERE IN UPPER CASE") { print "YOU ARE NOT ALLOWED ON THIS PAGE"; exit; } ?> PHP: Just paste on the head (begining) of pages you want to blocK
For this method is the only thing I would need to change be: if($country == "COUNRY NAME HERE IN UPPER CASE") { <<<< Put country here and if it's more then one would it look like this: if($country == "CANADA", "UNITED STATES", "CHINA") { print "YOU ARE NOT ALLOWED ON THIS PAGE"; <<<< I assume you put what you want here. And put quotes? Or is everthing in RED need to be changed? Thanks
i think it's a bad idea to rely on other services when you can implement your own solution on your own server easily. Check this website http://www.ip2nation.com/ * you can download the IP to country database for free * check the scripts they have there, you will see it's very easy to grab the info you need * Here's the script for country redirection http://www.ip2nation.com/ip2nation/Sample_Scripts/Country_Based_Redirect
whats that hard dude? replace print "YOU ARE NOT ALLOWED ON THIS PAGE"; with print "<meta http-equiv=\"refresh\" content=\"0; url=URL TO FORWARD TO\">"; in the script I gave upper
i have not tried it yet i will soon i just need to finish my other project but still looking for more samples if somebody have