Jump to content

Blocking Countries to certain PHP Pages?


drfate

Recommended Posts

Hi everyone,

 

is it possible to block certain countries from accessing individual pages?

 

For example, we have a competition page and we only want Australian Users from accessing it?

 

Can this be done through PHP? I don't want to block ENTIRE countries from the entire site, just a particular page?

 

Thanks in advance.

 

cheers,

Andrew

Link to comment
https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/
Share on other sites

I also found an example at;

 

GeoIPEnable On

GeoIPDBFile /path/to/GeoIP.dat

 

# Redirect one country

RewriteEngine on

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$

RewriteRule ^(.*)$ http://www.canada.com$1 [L]

 

So if I put this HTACCESS file in a directory called comp, I could use the above code to redirect?

 

cheers,

Andrew

You can get counter scripts which offer moderately good information of country referrals. I'd imagine you could run an if statement through one of those to redirect someone via a header if they're not from Australia, and offer a link requesting residential information for confirmation if someone actually from Australia was redirected.

 

That's all I can think of.

You can only do it with IP addresses. You will need to first figure out the IP range is for Australia. Then, at the top of the pages you want to allow only to Australians, you first get their IP address (google 'php get IP address'), check if it's within the range of Australian IP addresses, and if it's not, forward the user to a 'no access' page.

It is further more simple follow the links below:

 

http://mysqlandphp.net/viewtopic.php?f=3&t=24

 

You can first search for an ip address $_SERVER['REMOTE_ADDR'])

 

and with the ip address you can filter the country and city and using if command you will be easily able to restrict page.

 

Cheers,

 

That's very true, though in practice, rarely happens. First you have to find a proxy for that country that works, and second, you have to know how to set it up. Very few people can do both of those things. So while it's not foolproof by any means, it will work for the most part.

 

Also if you use a more comprehensive IE check, checking $_SERVER['HTTP_X_FORWARDED_FOR'] as well as $_SERVER['REMOTE_ADDR'], you can get the users IP instead of the proxy IP a lot of the time, which will block even more people, and make it more difficult for people outside the country to access.

 

It is further more simple follow the links below:

 

http://mysqlandphp.net/viewtopic.php?f=3&t=24

 

You can first search for an ip address $_SERVER['REMOTE_ADDR'])

 

and with the ip address you can filter the country and city and using if command you will be easily able to restrict page.

 

Which is exactly what I said.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.