Jump to content

Recommended Posts

Hi Professionals I have no code to show as I am still confused as to wether or not PHP is the right way forward

 

Here is my problem

 

I have 3 websites

 

UK, AU and NZ

 

What I am looking to do is serve the correct website to UK users and New Zealand users, it does not matter which country the AU users are in as they can have this website served to them in any country with the exception of the two mentioned above

 

Would PHP be the best for this or is there a better way of doing it

 

I have the correct hreflang tags in place I am just stuck on the Geo Location Serving part

 

I am looking to do similar to what trivago do or compare the market do for different countries

 

Thanks in advance professionals

 

Alan

Edited by oracle765

Is there a problem with prompting the user for which site to use? For example, what UPS and FexEx do. There's a pretty substantial advantage to prompting in that the user controls which site they use. With that said, defaulting and then offering a way to switch shouldn't be too bad.

 

Otherwise what you're looking for is generically called geolocation.

You can use something like this http://dev.maxmind.com/geoip/geoip2/javascript/tutorial/

 

Some people disable javascript, yes is a lot of sites that rely on javascript but they do it anyway.

In that case can do it server side with php

use curl/file_get_contents and a geo api , or have a local geo database

use a switch or if/else to determine which site needed to load

exclude the current site they are currently visiting

perform a header redirect to your new location unless they are already at it

 

I would set the location in a session or a cookie so don't have to keep doing the additional work each page load.

Check if the session or cookie exists first, if not run the geoip code

 

One thing you have to work out is if I was to visit from USA which site am I getting sent to.

Your site isn't handling every possible location, if is not one of the 3 you mentioned make one the default.

Edited by QuickOldCar

I played with maxmind a year or so ago, set it up in a local db and ran tests. On random generation tests in general a third of addresses weren't in it, yes they may not be assigned, but so many over numerous tests, so I ran ran some randomly collected addresses, there were even Google ip's which weren't in it, never mind my own! Also when tested with Tor and specified exit nodes, it often got it wrong. Yes, it was the free version.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.