Can anyone help me figure out how to display location specific information via a PHP script.
What I need is a way of changing currency/language automatically dependant on the physical location of my visitors. I've got a list of countries and their currencies stored in a mysql database, which can be used for determining the output.
Can anyone give me some assistance please? Better still, a script already out there that I can adapt....
If you can (reliably) get the country information, then its just a matter of querying your database.
So, assuming you get "US" from your location script, the language would be us_en (US English).
Now lets imagine that you have a table like this:
lang | currency | files
us_en | usd | /en/
You can use a query, such as "SELECT * FROM translations WHERE lang = 'us_en'; to get your current and file location, etc.
A better way to do this is to check for the Accept Language HTTP header, which will tell you what is the preferred language of the user. However, this approach does have its problems, namely :
1. If a user is in the US (en_us) or the UK - you might only get en as the Accept Language header, which will be no good if you want to decide on the currency symbol to use.
2. Like all other HTTP headers, Accept Language can be changed by the user agent (browser) -- and it may not always reflect the current locale of the user. For example, a traveller that is in France might be browsing your site from a laptop that he or she bought in the US which as en_us as the accept language header.
And finally, geoip lookup is not an exact science. I could be in Tahiti browing via a proxy that is in the UK, and your geoip will report my location as being in the UK (although I don't think why I would be browsing the web if I was in Tahiti).
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise
I've managed to get a database which already contains IP addresses and associated locations for these.
Of course, as you mention, if the visitor is browsing via a proxy then this may not work. I'll have to assume in that instance that the proxy user realizes this. AOL users may not be so lucky though. UK AOL users actually appear to come from the USA.
I've got a script pretty much sorted out now which looks at the last site visitor location and generates output based on that. Unfortunately that means there is a possibility that between page serves a new visitor may come along and mess up things if they are from another country. Cookies may have to become involved here me thinks!