Presenting visitors with regional content (province/state/county), amazon AWS - php

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.

Related

Is it possible to get website visitor's country and city without using an IP address database?

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']?

Can my mobile site send coordinates to the mobile phone's navigation app?

I have recently heard that a mobile website can push coordinates to the mobile phone's navigation app (or at least make it ask the user if they want to open it with their navigation app). I've done some google searching to no avail. I'm not sure if I'm just not using the right keywords or what, but I can't find this information. Does anyone know anything about this ability? And if so, can you give some links or examples? Thanks in advance.
Edit for a better understanding
I'm looking for a way to push a location to the navigation app so that the user can get driving directions. So the website will have a location of a shop, the user clicks the shop, it asks if they want to open their navigation app to get driving directions there, they press yes and are taken to the navigation app with the shop's location set.
Only way to do so is to pass data to Google or iOS maps - probably some other navigation apps are providing some url schemes but you're not able to check if such app is installed from browser level. When Google/iOS maps url is called inside browser Android/iOS will open proper application.
For Android and iOS <= 5 phones (for desktops also) you can just open URL:
// for example from JS
location.href = "https://maps.google.com/maps?saddr=Current+Location&daddr="+destination;
// or from PHP
header('Location: https://maps.google.com/maps?saddr=Current+Location&daddr='.$destination);
For iOS6 you can use similar address but change domain from maps.google.com to maps.apple.com.
You're looking for geolocation
The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. The API itself is agnostic of the underlying location information sources. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input. No guarantee is given that the API returns the device's actual location.

How to auto re-route other country traffic except USA to a default web page?

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.

Save users activity

I am a web developer and I want to design a commercial website to sell a customer's product. Sell and buy activities are important and I need to maintain user activity information to keep the site secure.
I want to write a dynamic website. I want to control all user activity and then decide whether to save user activity information in a database. Some of site's visitors are registered users and some are anonymous. I want to save online information such as ip address, username, page name, and date/time for my registered users.
I want to know:
How do I save a user's IP address?
What more do I need to save?
Saving each HTTP request details into database will work for low traffic web sites, but you will have performance issues in case of popular website, since writing to database in relatively slow operation.
Why not to use server HTTP logs instead?
All HTTP web servers create plain text log files which record remote user IP address, URL requested, etc. You can create activity report by writing your own script or using log file report tools. AWStats ( http://awstats.sourceforge.net/ ) is one of the most popular open-source tools for this.
On client side you can use Google Analytics to track user activity. It also provides means to track custom events:
_gaq.push(['_trackEvent', 'login', 'user_login', "custom data"]);
More info at: http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html
This option only tracks users with JavaScript enabled, so it won't show bots, crawlers or users having analytics blocking addons installed.
I'm not sure I understand all of your question...but to address at least one aspect of it, if the user is behind a proxy, then you have no way of determining what their real IP is. That's the whole point. The proxy is the one making the request and then forwarding it. Without asking the proxy yourself, you cannot determine that. With regards to what else you need to save, it depends entirely on what you want to do and you haven't done a good job of explaining why you are saving this data. If you can clarify that, perhaps we can help you a bit more in determining what data you should be saving.
Edit To address your clarification, if you wanted to be crazy, you could log everything that a person does. Every link they click, every product they view, etc. I don't necessarily advocate that as I find it a bit creepy, but there are definitely sites that do it. At the bare minimum, I would suggest logging what products people look at and then what products they buy. I would also log that information on a per-session basis. Basically, what products do people look at and then end up buying on the same trip to your store. I wouldn't worry too much about the "real" IP address. Most people won't be behind a proxy and those that are, you can't do anything about anyway.
How do I save a user's IP address?
$_SERVER['REMOTE_ADDR']
What more do I need to save?
That's quite strange question. It's your application, not someone's else. How can we guess what information you need?
However, at least one issue I can point out: a page name is not sufficient to log "all user activity". Query string and POST data usually contains important details on that activity.

How to know the original country of a website?

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.

Categories