Jump to content

Question: Block Traffic from certain countries

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
skilletsteve

skilletsteve

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
I am wondering if it possible to block traffic from certain countries in a PHP document. (Example: if I don't want users from Iran to be able to access my site, what would I need to do).

Thanks in advance
-Steve

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
This should get you started: http://forum.codecal...ighlight=target

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I'm curious to know why you want to block them. Are they causing problems?

#4
skilletsteve

skilletsteve

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts

Jordan said:

I'm curious to know why you want to block them. Are they causing problems?

I am getting started hosting a lot of proxy sites, and running adsense on the homepages. Users from Iran tend to use a LOT of bandwidth, and their clicks aren't worth that much on adsense.
so not 'problems' but I feel I would do better if they could not use my sites.

#5
skilletsteve

skilletsteve

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
(sorry to double post)

If anybody is wondering, I was informed that you can block traffic from different regions using the .htaccess file on the server.

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I've never heard of blocking using .htaccess but I do not see why it can not be done. Were you able to implement this?

#7
skilletsteve

skilletsteve

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
yes I was, quite easily actually. I just used the following code

Quote

order allow,deny
allow from all
deny from 62.60.128.0/17
deny from 62.193.0.0/19
Etc...

and for all the denies I simply went to this page IP address range lookup
and selected Iran.

#8
Chan

Chan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 204 posts
Wouldn't you need to do an .htaccess for every directory though?

#9
skilletsteve

skilletsteve

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts

Chan said:

Wouldn't you need to do an .htaccess for every directory though?

Yes, but I simply just downloaded the .htacess and them uploaded it into every directory. (And since what I run is proxy sites there were not that many directories. I am sure for other sites that are more content heavy this method may not have been the best choice.)