1

I was wondering if it's possible to work out if it is a user's first visit to the site and then redirect them to another site based on their country of origin (perhaps through GeoIP), but if they come back to the uK site then just show them the UK site.

Perhaps storing the first time visit check in a session?

So as an example, if it's someone's first visit to the .co.uk site and they are in Germany, then redirect them to the .de site.

However, if they visit the .co.uk site again - then we can tell their intent is to see the UK site and we let them view it until the session expires.

1

You could set a cookie for their initial visit containing their original country. Then you could set a session using the same method.

Cookies have a longer lifetime and won't get erased after the user leaves the site. This allows you to pull their country after they return. Setting the session variable holds their country site data for their current visit.

Then in your code (php but expression engine plugins could do some of this) do something like this in your page header

//test to see if the session has already been set
if (isset($_SESSION['country'])) {
   //redirect to http://test.$_SESSION['country'] if they are not already on that page;
} else {

//if it hasn't, test to see if the cookie is set
   if (!isset($_COOKIE['country'])) {
     //if not, get that information
     setcookie("country", //however you get your country);
   }

//Then start the new session and set country to the cookie
   session_start();
   $_SESSION['country'] = $_COOKIE['country'];

   //then redirect based off of the session variable
}

There are several plugins that might save you from having to write this in php, like Session Variables, Cookies, IPGeo

With these, I am sure you can recreate that code following the same logic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.