drfate Posted February 5, 2009 Share Posted February 5, 2009 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 More sharing options...
Brad7928 Posted February 5, 2009 Share Posted February 5, 2009 i don't know if this can be done, but wouldn't this be just blocking/allowing certain IP addresses? The more i think about it, i don't think you can use php to discriminate on IP addresses... wouldn't that be an apache thing? or .htaccess? Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-754958 Share on other sites More sharing options...
drfate Posted February 5, 2009 Author Share Posted February 5, 2009 You can block by .HTACCESS, however from what I can understand, it blocks access to your entire site which is not what I want to achieve Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-754959 Share on other sites More sharing options...
ilikemath2002 Posted February 5, 2009 Share Posted February 5, 2009 Make a new dir for the competition site, then put the .htaccess in there, it shouldn't affect the whole site. Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-754961 Share on other sites More sharing options...
trq Posted February 5, 2009 Share Posted February 5, 2009 You can block by ip, its a matter of finding out what ip's belong to what countries however. Even then, its easy for someone to work around. Take a look at geoip. Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-754962 Share on other sites More sharing options...
drfate Posted February 5, 2009 Author Share Posted February 5, 2009 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 Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-754969 Share on other sites More sharing options...
TheLoveableMonty Posted February 5, 2009 Share Posted February 5, 2009 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. Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-754974 Share on other sites More sharing options...
drfate Posted February 5, 2009 Author Share Posted February 5, 2009 Hmm... unfortuantely I cannot install GeoIP on my sever. does anyone know the code I would use in my .htaccess to band certain countries? e.g. domains with .au ? cheers, Andrew Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-755109 Share on other sites More sharing options...
haku Posted February 5, 2009 Share Posted February 5, 2009 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. Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-755112 Share on other sites More sharing options...
ashishag67 Posted February 5, 2009 Share Posted February 5, 2009 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, Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-755180 Share on other sites More sharing options...
aschk Posted February 5, 2009 Share Posted February 5, 2009 This is all flawed however because all someone has to do is use a proxy in the country in question and they'll be able to view the page surely? Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-755184 Share on other sites More sharing options...
trq Posted February 5, 2009 Share Posted February 5, 2009 This is all flawed however because all someone has to do is use a proxy in the country in question and they'll be able to view the page surely? Indeeed. I mentioned in my first reply that its very simple to work around. Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-755187 Share on other sites More sharing options...
haku Posted February 6, 2009 Share Posted February 6, 2009 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. Link to comment https://forums.phpfreaks.com/topic/143876-blocking-countries-to-certain-php-pages/#findComment-755664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.