i need to limit visits to my site from some regions.
how can i don't allow to visit my site from some country?(from Armenia for example)
(what is the way i must go? .htaccess? or maybe only by ip addresses?)
You can utilize geolocation. http://www.geoplugin.com/webservices/php has a solid API which will give you a good set of information on a region based on the visitors IP address. Using this you can log access to a database and cut off regions after X amount of visitors or compare against a blacklist in a Database.
Be aware, proxying users may be inadvertantly blocked (I.e. China user routes via Armenia. Or US user through Turkey etc).
Additionally this works in reverse, if someone truly wants to visit your site they can proxy around.
IP addresses; .htaccess won't help you here. CogitoErgoSum nails the geolocation of IPs.
Related
I am looking for a automatic way to link a website visitors's location to regionally limited content (not based on distance from lat/lon). The content is generated by a static site generator for each countries' province and will be delivered to the user from Amazon AWS. (Cloudfront I guess, we haven't yet decided precisely) provinces will each have their own static directory and for instance be accessed through their own url (//province.website.country)
So for instance a visitor from Beieren, Germany, must see only content that is published to Beieren, when the enter "website.de", get redirected to the beieren sub-url.
A possible solution is to present the user with a map in which they click on their region. However, we prefer to do this automatically when the information is present in the request headers/ip info.
I wonder what methods are out there except from comparing huge lists of ip ranges to ip/location databases and then getting the province from that location. For instance we are willing to use perverted methods like requesting google user data. But perhaps Amazon AWS provides a way to do this. We haven't been able to find it.
Most of all, we are looking for the fastest and most reliable way.
AWS does not provide any method of doing this.
Further, without asking the user where they are you generally have to rely on their IP address which is only really accurate in giving you the location of their ISP. I've seen IP address based geolocation be wildly inaccurate, so I wouldn't rely on it for anything important. If a user is on a mobile device you might be able to request GPS coordinates, but the user could always deny that request.
Currently my site - let's call it www.mydomain.com and it uses Google Analytics.
The site is UK based. We also have a mirror USA-based site on the same server, same domain - www.mydomain.com/us/, which uses a different Google Analytics ID.
Technically if some visitor comes to our UK site and if his IP address belongs to USA we would like to simply redirect the visitor to our US site by calling a PHP header location, i.e.
header("Location: www.mydomain.com/us/");
If this happens, then we are not sure what happens about GA "traffic" records on the site.
For example, on Google Analytics, if Visitor A types www.mydomain.com on their browser and goes to the site, then this is DIRECT TRAFFIC.
If we redirect them to www.mydomain.com.com/us/ it is still direct traffic.
If visitor B finds our site on Google search results, and clicks the search result to come into the main site, then it is ORGANIC TRAFFIC. However, if we redirect visitor B to the US site, I am not sure how Google Analytics in our US site treats this.
My questions are
Does it treat the customer as ORGANIC or DIRECT traffic for Visitor B?
If someone comes in via natural search engine rankings and gets redirected by us to the US site, I want them to be classified as organic traffic. How can I ensure that this happens?
General question about bots - we plan to redirect based on the user's IP. How can we avoid clashing with Google's IP so that Google (or any bot) can view our UK and US sites without any redirection from my code?
Some suggestions would be highly appreciated.
Many thanks!
The redirect will have as referrer your old page. So I'm pretty certain that GA would count it as an in-site link, however you have them named in GA.
This is the reason why you ideally would want to avoid doing sneaky redirects. Give your clients/visitors a choice instead of forcing them through a site - most websites tend to do this. What if I have an IP address from the US but am effectively from the UK due to a very small sub-range belonging to an UK-US ISP?
You'll need to map the IP ranges for the bots. Not an easy task.
I want to limit full functionality access to my website to users accessing it from USA only. Any users trying to access the website from any other country I want to identify that traffic based on IP or however possible that the user is not based in USA and display a default webpage like "We will be launching in your country soon" .. etc. message.
I have seen this functionality implemented by spotify.com and netflix.com and got a similar coming soon page when I tried to access the sites from India.
How do I implement this using PHP?
Thanks for any direction or insight.
You'll need to employ a geolocation service. Some are free, some are not:
Akamai, Quova, Digital Envoy (Digital Element service), Google (JavaScript), Maxmind, hostip.info, Geobytes, IP2Location, IP-GEO.
Some services you need to connect each time to make a query (you can cache the results). Other services allow you to download a database of IP-to-country mappings.
I want to know the original country of a website. I noticed that Alexa website can often detect the original country of websites. For example, Alexa can detect that the original country of stackoverflow.com website is USA and so on. How Alexa do this? and how i can do this? Thank You..
You can always read the country of any website from Alexa's Data from XML
core data
http://data.alexa.com/data?cli=10&url=http://www.flipkart.com
full data
http://data.alexa.com/data?cli=10&dat=snbamz&url=http://www.flipkart.com
It will be more reliable and easier than any other self developed approach
The other answers are fine, but bear in mind that many DNS registrations are protected by anonymization services, and that many sites are also hosted by providers in countries other than the one where the site's owner is.
example.com could be physically hosted on an American ISP's server, DNS provided by a Canadian company, and the site's owning company could be in Lesotho. You just can't tell these days.
In whois protocol you have one information "country" witch you must use it.
You could get this information out of the IP of a domain. You would need an IP-to-country database to look up that country.
Try this http://www.ip2country.net/
Most likely checks the DNS data for given domain
http://en.wikipedia.org/wiki/Whois
You can do a WHOIS lookup as mentioned in other answers to get the information about the website that were stored by the registrar and filled in by the user.
But you rely on an existing database of user-entered information and not actual technical data.
You can use a an IP geo-localisation service to get the location based on the IP. This may not always work for all IPs.
You could also do this for all the hops you go through, which you can list by doing a traceroute (with tracert on Windows or traceroute on *NIX) and see where your request is travelling to.
I am creating a poll script for a facebook fan page:
http://www.facebook.com/apps/application.php?id=115400635147687&v=app_115400635147687
I am getting the IP using:
$_SERVER['REMOTE_ADDR']
But the problem is that each time I refresh the page, or make an ajax call, the IP is changed everytime. Someone told me that facebook has many IPs, proxies.
Basically I need to save the IP in database, so that once a user from certain IP has voted, he should not be able to do so again.
What is the solution or alternative to this??
Blocking by IP is not really a reliable way of doing things (need to consider about people sharing the same public IP). Since it is a Facebook application, can't you instead block by the logged on Facebook account instead?
I assume the IP at the top of the linked page is what you're dealing with. If we do a whois:
$ whois 69.63.181.250
OrgName: Facebook, Inc.
OrgID: THEFA-3
Address: 1601 S. California Ave
City: Palo Alto
StateProv: CA
PostalCode: 94304
Country: US
NetRange: 69.63.176.0 - 69.63.191.255
CIDR: 69.63.176.0/20
We find that those IPs belong to Facebook's servers, not to your users.
If I understand what's happening correctly, when someone requests a page from your application, Facebook's servers request it from you on their behalf. In that case, you simply won't be able to get your users' IPs.
Note that when developing a fan page in Facebook, the Facebook servers essentially act as a proxy. That is, the user's browser asks Facebook for the page, then Facebook's servers make a request to your website to get the content. The Facebook server then rewrites all links and Javascript so that it any callbacks go through the Facebook servers first.
In the end, that means that you'll never see the user's "actual" IP address on your server: you'll only ever see Facebook's IP addresses.
This is done for privacy reasons, as I understand it. That is, the user will have to explicitly allow your application to access their profile before you will be able to get any "identifiable" information about them.
I found the perfect solution finally. Basically when you do ajax post, you can get the user's id using:
$_POST['fb_sig_user']