...

View Full Version : Redirect using Cookie data



Ann-Marie
05-24-2012, 08:38 PM
I have 4 shopping cart checkout pages.
3 share one cookie, #4 cookie is a different structure.
So the two cookies are stored in sequence.
It is rare that a customer would have both cookies saved but not impossible, especially for me doing tests from the same computer.
After processing the credit card, the bank returns to only one URL on my site.
On arrival I need to detect which checkout was processed and redirect to the appropriate "Thank you" page.
For the three of them that share a cookie I can save a numeric pointer but #4 uses a different cookie structure.
When I return I don't know which is current, both appear valid.
Any ideas?

Logic Ali
05-24-2012, 09:15 PM
So the two cookies are stored in sequence.

How cookies are stored is beyond your control and irrelevant. Do you mean that you have two separate cookies or one cookie storing one or two lots of information, or are you uncertain?

I think you had better show how you read cookies, because done properly there shouldn't be an issue here.

Ann-Marie
05-24-2012, 11:12 PM
If I open up document.cookie I can see the two cookies on the same string. I can search for a start and end key for each cookie and extract the stored data for each program. But both are valid cookies and I don't know which one was used to access the credit card processing.

I'm experimenting with storing a time stamp in each, that way when it returns from the bank processing the "redirect" program can find and check the time stamps and the most recent one "should" be the one that was used.

Unless there is an easier way to do it?

Logic Ali
05-25-2012, 01:51 AM
If I open up document.cookie I can see the two cookies on the same string. I can search for a start and end key for each cookie and extract the stored data for each program. But both are valid cookies and I don't know which one was used to access the credit card processing.Why not just set a third cookie that stores which checkout was used last?


function readCookie( cName ) /* Cookie reader */
{
var v;

return decodeURIComponent( ( v = ( document.cookie || "" ).match( "(^|\\s)" + cName + "=([^;$]+)" ) ) ? v[ 2 ] : "" );
}

Ann-Marie
05-25-2012, 04:25 AM
OMG, that's DEEP LOL, I'll study it.

How do I write to the new document.cookie? Everything I do within a document only modifies its own cookie.

In fact one thing I tried is having the document inspect all cookies when first loaded and trying to delete any "foreign" cookies so when it returns there is only one cookie in the file. But I couldn't find a way to do it. All I can do is modify the "current" document cookie. If I could "edit" the whole cookie file (including other documents) I could clean it up.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum