zappz
05-29-2004, 01:58 PM
I've given up trying to figure this out myself! :(:bawling:
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.... :D
azizny
05-29-2004, 06:54 PM
you need a script that finds that country??
if that is what you want to find, look here:
http://www.phptutorial.info/iptocountry/the_script.html
Salam,
zappz
05-29-2004, 07:23 PM
Funnily enough I was on that site not long ago.
What I need though is a PHP script that will determine the country of the visitor and then return data dependant on their location.
I can get the visitor location no problem, I'm just having problems figuring out how to use that information to generate a dynamic webpage based on the information.
Thanks for your time. :D
Burhan
05-30-2004, 02:53 AM
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).
zappz
05-30-2004, 10:47 PM
Thanks for that fyrestrtr,
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!
Thanks again.