Web Analytics Made Easy -
StatCounter Double Submit Technique? - CodingForum

Announcement

Collapse
No announcement yet.

Double Submit Technique?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Double Submit Technique?

    I have a form with numerous fields in it. On submit, I want to both update a local database and then essentially submit the form again to update a database on another site. Is there some way to do this?

    G

  • #2
    You can add all posted fields to a querystring and send them as such to the page on the other site, that will process them and update the db.

    To build the querystring, you could use something like
    PHP Code:
    $querystring 'sender=yourdomainname' 
    /*  include the above even if you don't actually use it 
    --> just a regular variable-value pair to make the loop 
          easier and faster */
    foreach ($_GET as $varName => $value){
       
    $querystring .= '&' $varName '=' $value ;

    Or you can reload the formpage with a javacript onload-submit in the bodytag, and the action then needs to be set at the other sites-page.

    Or you can set up a messagingsystem where you send the posted data (as an xml-file or so) to the other sites listener.

    If you need more info on the method of your choice, then post back with the code you managed to cook up
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      I would fsockopen() or similar a _POST request to the remote server at the same time you process locally , e.g. update your DB , then open the socket and submit , no need to refresh etc.

      I am pretty sure that Raf has a sample POST request using fsockopen in another thread here somewhere , try a search. (alternately look at something like snoopy
      resistance is...

      MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

      Comment


      • #4
        Raf,

        Thanks, good ideas. Querystring I had thought of, but I'm not completely sure how I would then transfer control to the other site - a header redirect, I suppose? The xml and messaging system approach is new to me - didn't know sites had a "listener" - got to do a little research on that. Thanks.

        G

        Comment


        • #5
          Originally posted by firepages
          I would fsockopen() or similar a _POST request to the remote server at the same time you process locally , e.g. update your DB , then open the socket and submit , no need to refresh etc.

          I am pretty sure that Raf has a sample POST request using fsockopen in another thread here somewhere , try a search. (alternately look at something like snoopy
          Euh ... no i don't. Not rely familiar with fsockopen to do a formproces on a remote server. If i would have such a setup, then I would do it over the client so that there is initiated a client-server interaction between the other server and the client, and the interaction between my own server and the client is ended.

          Note : the $_GET could also be a $_POST, depending on how you initially post the form
          Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

          Comment


          • #6
            note: posts crossed
            but I'm not completely sure how I would then transfer control to the other site - a header redirect, I suppose?
            Indeed.
            PHP Code:
            header('Location:http://www.seconddomain.com./somedirectory/somepage.php?' $querystring); 
            It's important to note that this redirect happens through the browser --> it's a browser-redirect, not a server-transfer like you can have in ASP (not sure how to do a transfer in PHP)

            The xml and messaging system approach is new to me - didn't know sites had a "listener" - got to do a little research on that.
            Sites have a 'listener" if you set one up... A webserver could also be viewed as a listener --> some soft that remains idle till it gets a request that it then will proces.
            But you can have other, non-wab listeners. For instance some javabeans etc.
            Last edited by raf; Feb 22, 2004, 10:23 AM.
            Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

            Comment


            • #7
              Euh ... no i don't.
              doh sorry , could have sworn it was you , I cant find the thread anyway so possibly wrong forum


              Gorilla checkout the sample POST via fsockopen at http://au2.php.net/manual/en/ref.stream.php , now thats for ssl but just change to http (there are examples in the fsockopen user notes as well) , though really snoppy noted above is a nice and easy to use ready made class for exaclty this.

              The 'listener' is indeed simply apache or whatever webserver , when you say you want to update the form on the other site , do you actually want to go to that site afterwards ? or just do the submittal ?

              if the latter..

              1 process your local code
              2 use snoopy or fsockopen to send your request to the other site
              3 wait for a reply (which you can ignore though its nice to know if the request worked)
              4 continue on
              resistance is...

              MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

              Comment


              • #8
                Thanks, lots to work with.... Yes, I just want a submittal, I dont want to go to the other site (which is windows/asp).

                G

                Comment


                • #9
                  I used the fsockopen apporach and it worked well... I wonder, couldn't these browser emulation techniques be used to query a remote database, even one on windows? Or is it not reliable enough?

                  G

                  Comment


                  • #10
                    I don't quirte understand your question, since you just queried the db on the remote server (--> the update)

                    Or do you mean like writing your own query and then run it against the dataserver on the other machine?
                    I suppose that would be no problem since you can write the query and send it as a variables value to the other server and then execute it there.

                    But it probably would be a bit risky to allow people sending in their querys like that ...
                    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

                    Comment


                    • #11
                      Can you explain why risky? The query is submitted to the remote site within a form essentially, the output comes back to my php script, and I strip out what I need. Is there a spot in there where folks could intercept? (Just to be clear, I would not have visitors submit querys that way -- but my script would be able to access info from the remote db -- so my script would be doing the query.)

                      G
                      Last edited by gorilla1; Feb 25, 2004, 04:08 PM.

                      Comment


                      • #12
                        Well, what would prevent Joe Hacker to open a socket himself and send in whatever query he wants ?
                        The action-page is public domain so you are then offering a query-box to everyone that knows about that page.
                        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

                        Comment


                        • #13
                          What do you mean by "The action-page is public domain". Are you referring to the code for sockets? ... Yes, if someone knows about the page they can query, but how would they know about it? Seems like you could also build a key into it?

                          G

                          Comment


                          • #14
                            The action page is the page that will process your request --> your request when you use a socket is nothing else then a regular http request (link, submit etc) So the page you send the query to would be a regular, webpage that is accessible by everyone. Hence public.
                            Yes, if someone knows about the page they can query, but how would they know about it?
                            You'de be surprised. I have some developmentaccounts where noone should know of. No links to or from them, and still i get all sorts of exotic people trying to access them.
                            And it's simply not a risk you can take (or that the owner of the other server can take)
                            Seems like you could also build a key into it?
                            Not sure about that. On the receiving end, it's nothing different from a reqular pagerequest so you can only use the protocols for normal webtrafic, like SSL which will exchange and use a sessionkey. Maybe you could set it up so that you can only connect if you have a private key (which needs to be created and exchanged in advance). I don't know. I wouldn't take the risk.
                            Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

                            Comment


                            • #15
                              Ah, ok , I see.

                              Comment

                              Working...
                              X