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.
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.
Is it possible to get the website visitor's location without using ip address ? I'm using geoplugin in my web app to get the visitors location using the IP address which I get from
$ip = $_SERVER['REMOTE_ADDR'];
but sometimes it does not return any data?
Yes ! Though without more details on your application, it's a bit hard to tell what to implement.
If this is a browser-based application, you could ask the browser to geolocate with navigator.geolocation.getcurrentposition and then send that data along with the request to php in the success callback.
Note that this call requires user permission, is asynchronous, and can take a long time to return.
Try W3C Geolocation API
It is an effort by the World Wide Web Consortium (W3C) to standardize an interface to retrieve the geographical location information for a client-side device. It defines a set of objects, ECMAScript standard compliant, that executing in the client application give the client's device location through the consulting of Location Information Servers, which are transparent for the application programming interface (API).
The most common sources of location information are IP address, Wi-Fi and Bluetooth MAC address, radio-frequency identification (RFID), Wi-Fi connection location, or device Global Positioning System (GPS) and GSM/CDMA cell IDs. The location is returned with a given accuracy depending on the best location information source available.
Reference
You tried that $_SERVER['HTTP_X_FORWARDED_FOR']?
I'm trying to build a database with records of unique visitors to a particular page on my website by obtaining their IP.
The code below fetches the visitor's IP:
$getip = $_SERVER['REMOTE_ADDR'];
echo "<b>IP Address: $getip</b>";
But I realize that this is very unreliable and inaccurate if various internet users are on a specific internet network and they all share the same IP address using different computers (Like a public cyber cafe or see example below).
Example:
XYZ Ltd uses a specific internet connection, if all the employees of XYZ Ltd are connected to the internet via the company internet connection and XYZ Ltd's IP Address is 69.18.107.24.
If some of the employee of XYZ visits my page, the code above would not give me unique IP address of the user's computer rather I'll keep getting the company IP address (69.18.107.24) which is inaccurate and deceptive cos the application would see it as the same visitor whereas there are different visitors using the internet connection IP.
How can I fetch unique user IP based on user's computer regardless of whether they are sharing the same internet connection.
I dont want to use PHP cookies cos some browsers do not support it while some users disable it or somthing.
Would be very grateful getting help with this...Thanks!
It is not possible to get the local IPs of computers behind a shared connection. Even if you could get them, they would not be unique, because they are reused - that's the whole point of NAT. You would have a lot of people using 192.168.1.1 or similar addresses.
If you want to differentiate between multiple machines that share the same IP address, you can add another factor, like the user agent string that tends to differ.
For example:
<?php
md5(
$_SERVER['REMOTE_ADDR'] .
$_SERVER['HTTP_USER_AGENT']
);
// 80b567b7c7ccfbda75a9712f16ca4429
would give you a hash that would only be identical if two users share the same IP address and have the same browser and operating system version.
Visit Panopticlick to find out more about "browser fingerprinting". Surprisingly, browsers are almost unique in the combination of their configuration. If you bring in client-side analysis with Javascript, where you can access display resolution, installed plugin versions and other details, you can easily differentiate between users that have a shared IP.
You cannot. IP addresses are a data packet delivery mechanism. Nothing guarantees that an IP address in a specific network is unique to one specific machine, there simply is no such correlation. The machine has a unique address inside its network, but this address may not be globally unique (and you cannot get this IP anyway). The public IP of the shared proxy is unique on the public internet, but nothing dictates that it must correspond to one physical machine.
IPs != machines, live with it.
Here is the answer to your question:
<?php
echo "IP address".$_SERVER["REMOTE_ADDR"]
echo "LAN Address".$_SERVER["HTTP_X_FORWARDED_FOR"]
?>
This is not a sure way to get a unique visitor.
The LAN address can be spoofed easily.
Also many companies use a DHCP server that with give out new LAN IP's every day.
Cookies would be the "only" real way of checking.
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 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.