3 Replies Latest reply on Nov 19, 2011 9:59 AM by ACS LLC

    Double Posting of forms/Two sessions

    ACS LLC Level 1

      We have a really strange issue, wondering if anybody else has even had this


      We're developing an Android app which utilizes web content from the CF8 server by using a browser that we build into the app.


      The app allows end users to complete a form (from our server - just a web page really) and then post it, it's really no different than a web site.


      Here's the problem, the code started to crash yet looked perfect and after some digging I found that what appeared to be happening was that the 'browser' was some how posting twice, two separate instances, I have a UUID that writes to the dbase with the record, that was unique in the TWO records that it created, I put a CFABORT at the end of the SQL insert statement, and still got two records, I also had it update a counter in the dbase, and I found that I still got two record updates, with the CFabort in place it showed that there was no code AFTER the sql that could cause it to loop back into the code, so it must be hitting the page twice (no checks for dupe records as this was not expected)


      I am guessing it's the app, it doesn't happen in firefox, or the phones native web browser outside of the app.


      I'm going to play around with the application.cfm which does check for a session, and if one does not exist kick the user back to the index.cfm, and also look for any initially provided URL variables and set them into the system, I am wondering if that redirect is messing it up.


      Anyway, it's a strange one, thought I'd throw it out there for comments





        • 1. Re: Double Posting of forms/Two sessions
          Dan Bracuk Level 5

          If the intent is to prevent duplicate records, the best place to do so is your insert query.


          insert into yourTable


          select distinct values

          from someSmallTable

          where not exists

          (stuff for duplicate records goes here)


          Then it doesn't matter how the attempt is made.


          As far as the double form submission goes, I've seen something similar.  We used to get a double page request without a form scope at all.  It was intermittent and we never did figure it out.  It does not appear to be happening to us anymore.

          • 2. Re: Double Posting of forms/Two sessions
            ACS LLC Level 1

            unfortunately it's a set of pages that the user continues to loop through as they complete various forms for our advertisers offers, the list of forms is descreased in a list that is held in a session, amongst other changes to the sessions. The page that is 'visible' is the 'second' one, so the first hit writes the record, does it's thing with the sessions, so when the visible page hits the server it crashes because the session variables were changed by the first invisible hit.


            Not only does this happen on form submits, but even on the initial page which serves the offer list to them, no submit on there, and like you it appears to be intermitant

            • 3. Re: Double Posting of forms/Two sessions
              ACS LLC Level 1

              After taking a bit of a break from this because it was driving me nutts! I went back to the very beginning and did unearth a clue, what it tells me I'm not sure.. CF or App issue, not quite sure still..But check this out.


              My application.cfm file sets up the session, as below:





                  sessionTimeout="#createTimeSpan(0, 0, 30, 0)#"



              <!---// make sure cookies expire when the user closes their browser //--->

              <cfif structKeyExists(cookie, "cfid") and structKeyExists(cookie, "cftoken")>

                  <cfset localCFID = cookie.cfid />

                  <cfset localCFTOKEN = cookie.cftoken />

                  <!---// reset the cookies //--->

                  <cfcookie name="CFID" value="#localCFID#" />

                  <cfcookie name="CFTOKEN" value="#localCFTOKEN#" />




              <CFIF NOT #IsDefined('session.aff')#>

              <CFINCLUDE TEMPLATE="defaultvariables.cfm">

              <CFSET session.aff="0"><CFLOCATION URL="index.cfm"></CFIF>


              Is checks to see if a sessoin has already been established, if not it includes the defautvariables.cfm template which basically just looks for a few URL variables initially passed to the server from the app (the app goes to index.cfm first shot with some variables), the variables are set into the session and then the code redirects back to index.cfm. I have to have the redirect because the rest of the pages need to have a session, so if session.aff is missing, it'll kick back to the index.cfm from any point. One thought is to do away with that and put all the other active pages in their own directory, but I'm not sure I'll benefit from that.


              Anyway, when the app hits the index.cfm page, without a session established, I get a double hit on the server, it clocks up two of everything, but when I go back to is with the session active, one hit, if I close the app, clear the session go back again, same thing, 2 hits, now this is just this page, not sure why the other pages are doing it further down the road, but perhaps this initial 'confusion' brought on either in the app or in the CF is causing it to go wrong further down the road.


              I may try breaking it all apart so it hits the index.cfm, checks the session and if there isn't one, create and check for url variables, then when it's done, kick over to another page in a sub folder with all of the other files.. then the application in the sub folder just checks for the session.aff and if not present kicks back to the index.cfm, the only advantage with that is that I can stop the page redirecting back to itself, the initial index.cfm.. purely experimental, surely what I have should work.