Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Redirect using Cookie data

    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?

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Ann-Marie View Post
    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.

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Ann-Marie View Post
    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?

    Code:
    function readCookie( cName ) /* Cookie reader */
    {
      var v;
    
      return decodeURIComponent( ( v = ( document.cookie || "" ).match( "(^|\\s)" + cName + "=([^;$]+)" ) ) ? v[ 2 ] : "" );
    }

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •