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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.