21 Replies Latest reply on Jul 27, 2006 12:00 PM by TonyP

    Form Redirect

    TonyP
      Hi, I'm trying to redirect a form post from one http sever to another.
      I have two coldfusion pickupdepot scripts that accept IPN posts from paypal. Sometimes paypal posts to the wrong one, so here is what i need to do.
      I want pickupdepot1 to redirect certain posts to the other pickupdot2. I know its not as simple as a redirect.
      I want pickupdepot1 to see the incoming post from paypal, then based on my query, Just forward the post to another url. can this be done?

      Thanks

      Tony Paolillo
        • 1. Re: Form Redirect
          MikerRoo Level 1
          You can do this with a cfhttp and GetHttpRequestData() although this could get messy quickly.

          Perhaps a more productive tack is to arrange your servers in a true clustered manner.
          • 2. Form Redirect
            BKBK Adobe Community Professional & MVP
            pickupdepot1.cfm
            ===============
            <!--- see the incoming post from paypal, then based on my query, Just forward the post --->
            <cfscript>
            getPageContext().forward("pickupdepot2.cfm");
            </cfscript>




            corrected: </cfscript>



            • 3. Re: Form Redirect
              MikerRoo Level 1
              quote:

              Originally posted by: BKBK
              pickupdepot1.cfm
              ===============
              <!--- see the incoming post from paypal, then based on my query, Just forward the post --->
              <cfscript>
              getPageContext().forward("pickupdepot2.cfm");
              <cfscript>




              Clever.
              But perhaps you should TEST your code. Then you would see that form information is not preserved.

              Anyway, TP is asking for help on a dubious endeavor. The only real need, for which, is malicious hacking.

              • 4. Form Redirect
                BKBK Adobe Community Professional & MVP
                > Anyway, TP is asking for help on a dubious endeavor. The only real need, for which, is malicious hacking.
                Perhaps. However, there can be a legitimate need to forward some transaction details. We implement one like this

                processPayPalTransaction.cfm
                ==========================
                <!--- Process form post from PayPal. Run query to get client details --->
                <cfscript>
                getPageContext().forward("clientPayPalConfirmation.cfm");
                </cfscript>

                clientPayPalConfirmation.cfm
                ========================
                Send client e-mail confirming receipt, plus relevant identifying information, with thanks. If transaction failed, confirm as well.

                > Then you would see that form information is not preserved.
                We forward the variables in Request scope, not in form scope.





                • 5. Re: Form Redirect
                  TonyP Level 1
                  Thank you BKBK for your replies. As MikerRoo is entirely wrong, with his quick, rude and childish statements. I do have a legitimate reason for this request.
                  As you might know paypal has an IPN feature. This feature allows you to execute a script when a customer makes a purchase from you. Well, I have 2 pickupdepots for my customers and I need 2 different IPN scripts. Paypal only supports one, so I needed to use a NOTIFY_URL in the other website forms.
                  All works good UNTIL, if for some reason paypal cannot talk to your script on the FIRST try, paypal will try again later BUT it will do the rest of its retries using the DEFAULT IPN script link and does not retain the NOTIFY_URL that you originally sent it.
                  So what I need to do is just set a "CFIF" statement looking at the post from paypal and if it’s at the wrong url, to forward it to the other url.

                  I will try the <cfscript> you mentioned. (Thank You).
                  I have one quick question though, If I forward the request over from pickupdepot1 to pickupdepot2, Paypal requires a postback to authenticate the purchase, will that post back to paypal OR the sending link? (pickupdepot1)
                  If it does not carry over the feature to post back to paypal, that’s ok, because their both my scripts, so i can just do some CFIF's and trust one another.

                  Thanks alot for your help BKBK
                  • 6. Re: Form Redirect
                    BKBK Adobe Community Professional & MVP
                    As MikerRoo correctly pointed out, the above forwarding mechanism cannot send form-scoped variables. It can however forward the request scope. You can use that to forward all your form variables in one fell swoop, thus

                    pickupdepot1.cfm
                    ===============
                    <!--- This block contains variables in form scope, say, form.x, form.y, etc --->
                    <cfscript>
                    Request.z = getHTTPRequestData().content;
                    getPageContext().forward("pickupdepot2.cfm");
                    </cfscript>

                    pickupdepot2.cfm
                    ===============
                    <cfdump var="#Request#">

                    • 7. Re: Form Redirect
                      Mr Black Level 1
                      Miker is 100% correct. You cannot use .forward to redirect to ANOTHER server. You can use CFLOCATION, but it can be only GET request (will loose posted data, unless you provide them in URL). Also, since the original post is not happening from a real user/browser, redirect may not work correctly, if PayPal does not process re-directs (because of security reasons, for example).

                      So, the only real opportunity you have in your situation is to use <cfhttp> to call the required page on your other server, wait for its response, post the confirmation.
                      • 8. Re: Form Redirect
                        TonyP Level 1
                        I Hate to sound Novice here but im just not sure of the code to use. I have reviewed the <http> tag and cannot figure out how to do what you mentioned Mr Black.
                        I however do understand what your saying, that the CFLOCATION will not work because of the Form POST vars will be lost.
                        My code now on pickupdepot1 will proccess the Paypal security feature like this:
                        <cfhttp url="https://www.paypal.com/cgi-bin/webscr?#str#" method="get" resolveurl="false">
                        </cfhttp>
                        (this is a post back to Paypal to see if the payment is legit)

                        Then If all is good (<cfif #cfhttp.filecontent# is "verified">), the payment at this point is truly coming from paypal and has passed the security)
                        Now that the security check is completed, I can send the form fields to another server.
                        I do also have right below that line this:
                        <cfloop index="locfield" list="#form.fieldnames#">
                        <cfset locfield=urldecode(evaluate(locfield))>
                        </cfloop>
                        This is to convert the posted variables to local variables. Will that help me or does that not matter?
                        Im just not sure of the <http> syntax to send the posted data to another url. For some reason its just not hitting me.

                        Tony




                        • 9. Re: Form Redirect
                          Mr Black Level 1
                          At this point you know the entire story about the payment. So, you can post whatever you want. If you are not sure about the syntax, perhaps, the documentation will help you. It is not so different from what you already doing with PayPal confirmation. Maybe the original value of STR plus some variable that holds confiramtion status. And, by the way, you can use GET for this.
                          • 10. Re: Form Redirect
                            TonyP Level 1
                            Ok, Thanks for everyones help.

                            Tony
                            • 11. Re: Form Redirect
                              BKBK Adobe Community Professional & MVP
                              Im just not sure of the <http> syntax to send the posted data to another url. For some reason its just not hitting me.

                              This works. Try it.

                              pickupdepot1.cfm
                              ===============
                              <!--- The CFHTTP to PayPal has just run. This block contains variables from PayPal in form scope, say, form.x, form.y, etc --->
                              <cfscript>
                              Request.z = getHTTPRequestData().content;
                              getPageContext().forward("pickupdepot2.cfm");
                              </cfscript>

                              pickupdepot2.cfm
                              ===============
                              <cfdump var="#Request#">
                              • 12. Form Redirect
                                BKBK Adobe Community Professional & MVP
                                You cannot use .forward to redirect to ANOTHER server.
                                Mr Black, I thought TonyP sought to redirect to another page, not to another server. Your point, that forward() is not a solution from one server to another, is correct. However, I cannot see any advantage in carrying out the process on two servers.



                                • 13. Re: Form Redirect
                                  TonyP Level 1
                                  I will try the forward() script. The links are like this: " http://www.pickupdepot1.com/ipnscript.cfm" would get forwarded to " http://www.pickupdepot2.com/ipnscript.cfm".

                                  Will the forward() still work?
                                  • 14. Re: Form Redirect
                                    BKBK Adobe Community Professional & MVP
                                    I will try the forward() script.
                                    No need.

                                    Will the forward() still work?
                                    It wont, the reason being that the argument, x, in getPageContext().forward(x) must be a relative URL.

                                    Here's a good way to pass form variables from one server, pickupdepot1, to another, pickupdepot2. While you're on pickupdepot1, store the form variables to a database. At pickupdepot2, read the variables from the database.

                                    • 15. Re: Form Redirect
                                      TonyP Level 1
                                      Hi BKBI, I already save all the incoming data to a database. However I dont see that as being a feasable solution. I would have to ping the other server or something to let the other server know that there was a purchase for them and "come get it". Also would have to open a door for access from the other server.
                                      Couldn't I somehow grab the form vars comming in and maybe wrap them in a wddx packet or somehow RE-proccess the form vars and the POST it to another url?I already have somehting like this:
                                      <cfloop index="locfield" list="#form.fieldnames#">
                                      <cfset locfield=urldecode(evaluate(locfield))>
                                      </cfloop>
                                      that converts the posted vars to local vars, So i know we can proccess the incomming vars. Now just what do we do with them. Maybe proccess them into a struct and then send the struct to another server?
                                      One thing though, However it does it, The recieving end is looking for posted data from a form. I can change the script to allow ANY data from this other server, but it must be posted to this script.

                                      There has to be a way that I can either roll up the form vars and the post it to another url, or bounce the post to another url. I wish i knew what it was.


                                      Thanks

                                      Tony

                                      • 16. Re: Form Redirect
                                        BKBK Adobe Community Professional & MVP
                                        However I dont see that as being a feasable solution. I would have to ping the other server or something to let the other server know that there was a purchase for them and "come get it". Also would have to open a door for access from the other server.
                                        All of that is not necessary at all. After processing the form, the first server only has to open the page on the second server that runs the query.

                                        Couldn't I somehow grab the form vars comming in and maybe wrap them in a wddx packet or somehow RE-proccess the form vars and the POST it to another url?
                                        If you insist that the variables must arrive at the second server as form-scoped variables, then proceed as follows. After receiving the form variables at pickupdepot1 dynamically create a new form whose action attribute is " http://www.pickupdepot2.com/ipnscript.cfm". Create a field with the same name as each field of the incoming form. Give each the value that corresponds to the name. For example,

                                        <input type="hidden" name="ITEM_NAME" value="#FORM.ITEM_NAME#">

                                        When the dynamic form is submitted to pickupdepot2, the variables will arrive there as form-scoped variables.


                                        • 17. Re: Form Redirect
                                          MikerRoo Level 1
                                          quote:

                                          Originally posted by: BKBK
                                          All of that is not necessary at all. After processing the form, the first server only has to open the page on the second server that runs the query.



                                          You're quite right. Your suggestion should have worked for legitimate needs. (Although proper server configuration is the best solution)

                                          That it didn't, means that TP is either a moron or a hacker (or both).

                                          Form repost techniques, across servers, are used by phishers.
                                          Do you want to help a hacker?
                                          • 18. Re: Form Redirect
                                            TonyP Level 1
                                            To keep the quality of this forum high, Ill ignore MikerRoo.
                                            I like the idea of just running a loop, proccessing the form vars as you said BKBK, Then I could use java to post the form to the other server.
                                            That should work. Im diggin that idea.

                                            Ill let you know how it goes, Thanks again

                                            Tony
                                            • 19. Re: Form Redirect
                                              TonyP Level 1
                                              Hi BKBK, Thanks fo ryour help. Here is the solution that I used:
                                              <cfif #form.business# eq "payments@mydomain.com">
                                              <cfhttp method="Post" url=" http://www.mydomain.com/pickupdepot/ipnpage_cfpp.cfm">
                                              <cfloop index="locfield" list="#form.fieldnames#">
                                              <cfhttpparam type="Formfield" value="#urldecode(evaluate(locfield))#" name="#locfield#">
                                              </cfloop>
                                              <cfhttpparam type="Formfield" value="Verified" name="cfpp_verification">
                                              </cfhttp>
                                              <!--- The System has sent the data to The New Pickup Depot and now is going to Abort! --->
                                              <cfabort>
                                              </cfif>

                                              This works great. It sends the data over then aborts.
                                              Thanks for all your help

                                              Tony
                                              • 20. Re: Form Redirect
                                                BKBK Adobe Community Professional & MVP
                                                This works great.
                                                Nice you found what you've been looking for; even nicer you found it.

                                                • 21. Re: Form Redirect
                                                  TonyP Level 1
                                                  Most of the thanks goes to you for helping. I learned about CFHTTP and you steered me in the right direction.

                                                  Thanks Again.

                                                  Tony