Jump to content

Trying to Redirect with cookie or with zip from url


danjapro

Recommended Posts

I have this javascript here, I am trying to gather the zip and referrer and aaa_redir_url from the URL, which I have them being called as a variable.

But if there is not zip in url, to then redirect to set location.

 

I need a little assistance with this.

 

here is how I am calling my variable that I need to pass

 

        <script type="text/javascript">
		var tqsRedirectChecker = new TQSRedirectChecker({
			aaa_redir_url:  http://aaa.com/memberdeals,  //need to repoint this, if the users does not have zip and devicecd
			timeWindow: 1800000, //milliseconds
			zip: "<?php if (isset($_REQUEST["zip"])):echo $_REQUEST["zip"]; endif; ?>",				
			referrer: "<?php if (isset($_REQUEST["referrer"])):echo $_REQUEST["referrer"]; endif; ?>",
		});
		tqsRedirectChecker.validateTqs();
	</script>

 

Here I am trying to perform the redirect, per the zip and reffer and then if it is not loaded in url go to aaa_redir_url, but if there is a zip and reffer in url go to a set url, that.

 

If there is a way to make it into a cookie and then pass it, will be greate if not, just above request will be gratefully appreciated:

 

var TQSRedirectChecker = function(config) {

// This object expects a configuration JS object with all of the following parameters
var allowed_clubs_array = config.allowed_clubs_array;
var invalid_club_url = config.invalid_club_url;
var invalid_ts_url = config.invalid_ts_url;
var aaa_redir_url = config.aaa_redir_url;
var timeWindow = config.timeWindow;
var zip = config.zip;
var referrer = config.referrer;
var recipient_id = config.recipient_id;
var ets = config.ets;
var club = config.club;

// Get the current system time
var systemTime = new Date();
// Initialize the encoding / decoding key using the following map:
//
//    1 <-> E
//    2 <-> A
//    3 <-> C
//    4 <-> B
//    5 <-> D
//    6 <-> F
var key = new String("EACBDF");


// *
// * PUBLIC METHOD to run the TQS Check
// *
this.validateTqs = function(){
	// Checks to see if the request is a redirect from TQS.  If
	// so, then it validates the credentials.  If the request fails
	// validation, the request will be redirected to the "I'm sorry"
	// page.
	if( isEmailClickThru() ){
		alert("Recipient ID: "+recipient_id);
		return;
	}
	if( !isTqsRedirect() ){
		//alert("Not TQS...sending to aaa.com/MemberDeals");
		window.location = aaa_redir_url;
		return; 
	} else {
		alert(referrer + " | " + ets + " | " + club + " | " + timeWindow);
	}
	if( !isValidClub() ){
		alert("invalid club");
		window.location = invalid_club_url;
		return;
	}
	if( !isValidTqsTime() ){ 
		alert("invalid time");
		window.location = invalid_ts_url;
		return;
	}
}


// private method to check whether or not the incoming request is a referral from the partner redirect system.
var isEmailClickThru = function(){
	var isEmailClick = false;
	if( recipient_id != undefined && recipient_id != null && recipient_id != "" ){
		isEmailClick = true;
	}
	return isEmailClick;
};

// private method to check whether or not the incoming request is a referral from the partner redirect system.
var isTqsRedirect = function(){
	var isTqsRedir = false;
	if( referrer != undefined && referrer != null ){
		if(referrer == "aaa" || referrer == "caa"){
			isTqsRedir = true;
		}
	}
	return isTqsRedir;
};

// private method to see if the time parameter is within the window
var isValidTqsTime = function(){
	var isWithinTime = false;
	var etsTime, etsTimeDecoded;

	if( ets != undefined && ets != null ){
		etsTime = ets;
		if( !(etsTime == null) && !(etsTime == undefined) && !(etsTime == "")){
			etsTimeDecoded = decodeTime(etsTime);
			if(etsTimeDecoded > (getGMTTime(systemTime) - timeWindow) && etsTimeDecoded < (getGMTTime(systemTime) + timeWindow) ){
			   isWithinTime = true;
			}
		}
	}

	return isWithinTime;
};


// Private method to validate whether a club code is participating in the program
var isValidClub = function(){
	var isClubAllowed = false;
	if( club != undefined && club != null ){
		for(var i=0;i<allowed_clubs_array.length;i++){
			if(allowed_clubs_array[i]==club){
				isClubAllowed = true;
				break;
			}
		}
	}

	return isClubAllowed;
};

Link to comment
Share on other sites

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.