The title says it all...ultimately, i need to redirect based on a map choice, but this would be a start. Assuming a cookie gets set.

thanks!

Comments

funkeyrandy’s picture

Anyone?

TechDude’s picture

I'm trying to achieve something similar. I have the initial selection through the flags module and session API. Not sure how to redirect on a revisit. Would love to find out what others think.

funkeyrandy’s picture

in going to post this because nothing i did in php worked and my hair was falling out...had to resort to javascript, but it works well! This is for a multi domain setup with a redirect to the last visited page if it was not the primary domain:

<script>
function createCookie(name,value,days) {
	 if (days) {
		  var date = new Date();
		  date.setTime(date.getTime()+(days*24*60*60*1000));
  		var expires = "; expires="+date.toGMTString();
	 }
	else var expires = "";
	document.cookie = name+"="+value+expires+";domain=.yourprimarydomain.com;path=/";
}

function readCookie(name) {
	 var nameEQ = name + "=";
 	var ca = document.cookie.split(';');
 	for(var i=0;i < ca.length;i++) {
  		var c = ca[i];
  		while (c.charAt(0)==' ') c = c.substring(1,c.length);
  		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 	}
	return null;
}

function eraseCookie(name) {
	 createCookie(name,"",-1);
}

// script body
// setting default values for parameters
  var loc = document.location.toString().split('/');
if(loc[2] == "yourprimarydomain.com") {

  var dsLVPURLMainPage = "http://" + loc[2] + "/" + loc[3];
}

if(typeof(dsLVPNotification) == "undefined")
  var dsLVPNotification = "You have been automatically redirected to last visited page on the site.";

//redirecting user to last visited page if he
//enters the site through main page
if(document.location == dsLVPURLMainPage) {
  //redirect only if user navigates to main page first time
  //in current session (if referrer not contains main page address)
  var storedData = readCookie("dsLVPURL");
  if(document.referrer.indexOf(dsLVPURLMainPage) == -1 && storedData != null) {
    LastVisitedPageURL = decodeURI(storedData);
	var lastbase = LastVisitedPageURL.toString().split('/');
	
    if(LastVisitedPageURL != null && LastVisitedPageURL != dsLVPURLMainPage && lastbase[2] !='yourprimarydomain.com') {
      document.location = LastVisitedPageURL;
      dsLVPMessage = dsLVPNotification;
    }
  }
}
// storing last visited page for a year in cookie
if(typeof(dsLVPDisabled) == "undefined")
  createCookie("dsLVPURL", encodeURI(document.location), 365);

</script>