Re-using POST data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adriann
    New Member
    • Aug 2006
    • 25

    Re-using POST data

    Hi. I'm new to PHP but I'm making progress.

    However, I'd like to know if I can use all the data in the $_POST array and send to the next page.
    Essentially, I perform a check of the content (which can vary), before sending it on to another page which will handle the real processing of the required information.

    Can this be done easily, or do I have to extract all the individdual paramteres and re-process them somehow to pass on to the next page.

    My Post data contains nested arrays.

    What are your recomendations?

    thanks
    Adrian
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    I f u want to get the variable multiple page using SESSION to get the value all the pages

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Actually, there are 3 ways to accomplish this:
      • Store the variables in the $_SESSION array. That way the called script can retrieve them also via the $_SESSION array. To use this, you must have called session_start() in order to be able to use the array.
      • Use the $_GET array. In this case you construct a URL of the script to be called with the parameters concatenated, e.g. "form.php?v1=va r1&v2=var2 etc". The form.php script can now retrieve the values via the $_GET array.
      • Use the $_POST array. To use this you also construct the URL as in the previous, but now you pass it to CURL with the POST option. The receiving form.php can now access the values via the $_POST array.


      Take your pick!

      Ronald :cool:

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by ronverdonk
        • Use the $_POST array. To use this you also construct the URL as in the previous, but now you pass it to CURL with the POST option. The receiving form.php can now access the values via the $_POST array.
        Ronald, could you go into a little more detail about this method please? :-)

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Glad to, Banfa. I'll just start with the definition given by Zend:
          cURL and libcurl are libaries that allow a webserver to transfer files with a remote computer using a variety of Internet protocols. The libaries are highly configurable, allowing practically any type of client-server request to be peformed. By using these tools, a webserver can act as a client, creating and responding to requests using any technology built on HTTP, like XML-RPC, SOAP, or WebDAV.
          And one by Wikipedia:
          cURL is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, TFTP, Telnet, DICT, FILE and LDAP. cURL supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, Kerberos, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM and Negotiate for HTTP and kerberos4 for FTP), file transfer resume, http proxy tunneling and many other features. cURL is open source/free software distributed under MIT License.

          The main purpose and use for curl the command line tool is to automate unattended file transfers or sequences of operations. It is for example a good tool for simulating a user's actions at a web browser.

          Libcurl is the corresponding library/API that users may incorporate into their programs; cURL acts as a stand-alone wrapper to the libcurl library. libcurl is being used to provide URL transfer capabilities to numerous applications, Open Source as well as many commercial ones.

          More than 30 different language bindings are available for libcurl.
          Curl is free and open software that compiles under a wide variety of operating systems. Currently there are approx. 35 language bindings available.

          Following addresses the reply I gave in this forum about POSTing via CURL. Just 2 samples (sending and receiving) that I got from the Zend site and use myself (adapted to my site):
          [PHP]-------------- POST variables via curl ----------------------------------
          <?php
          //
          // A very simple PHP example that sends a HTTP POST to a remote site
          //

          $ch = curl_init();

          curl_setopt($ch , CURLOPT_URL,"ht tp://www.mysite.com/tester.phtml");
          curl_setopt($ch , CURLOPT_POST, 1);
          curl_setopt($ch , CURLOPT_POSTFIE LDS,
          "postvar1=value 1&postvar2=valu e2&postvar3=val ue3");
          curl_exec ($ch);
          curl_close ($ch);
          ?>
          ------------------ and this is to test the $_POST array ---------------
          <?php

          echo '<h3>Form variables I received: </h3>';

          echo '<pre>';
          print_r ($_POST);
          echo '</pre>';

          ?>[/PHP]
          There is quite some information about cURL, see:

          The developers of Curl (Daniel Stenberg and 500 others): http://curl.haxx.se/libcurl/php/
          PHP site: http://nl3.php.net/manual/en/ref.curl.php
          Zend site: http://www.zend.com/pecl/tutorials/curl.php
          PHP-It site: http ://www.phpit.net/article/using-curl-php/
          PHP Freaks site: http://www.phpfreaks.com/tutorials/49/1.php
          Higherpass site: http://www.higherpass.com/php/tutori...ote-Servers/1/ and http://www.higherpass.com/php/Tutori...emote-Servers/
          Yahoo site: http://developer.yahoo.com/php/howto-reqRestPhp.html
          bobcares.com: http://bobcares.com/article47.html

          But, when you look around (e.g. Google, Yahoo), you'll find many more stuff on the net.

          When you want, I can send you a Word document "CURL: Client URL Library" by Mr. MA Razzaque Rupom.

          Ronald :cool:

          Comment

          • iam_clint
            Recognized Expert Top Contributor
            • Jul 2006
            • 1207

            #6
            you don't have to go as far as that just to retrieve these values my friends...


            use hidden text fields in a form if your using a form.

            if your not using a form make the links call the form to submit.

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              That was not the point. Question was just how to pass data from one page to another. Making an extra form requires the user to click an extra link, and that was not the point here.
              Passing it via the URL exposes your parameter data to an outside onlooker.

              Posting it without using a form is the issue here, hence CURL.

              Ronald :cool:

              Comment

              • adriann
                New Member
                • Aug 2006
                • 25

                #8
                thanks all for your detailed replies.
                I'll have to do some research on these approaches due to inexperience, but thanks for guiding me in the right direction.

                Comment

                • RonS
                  New Member
                  • Sep 2006
                  • 4

                  #9
                  Wow great thread. I actually have a similar problem.

                  While running a php script on user-supplied info from a form, I need to send some of that data to a php script running on another server (which does a database lookup), and get back a response.

                  This is the way that I've thought of (and successfully tried) doing it

                  [php]<?php
                  $foo = urlencode($food ata);
                  $bar = urlencode($bard ata);

                  $response = file_get_conten ts("http://example.com?foo =$foo&bar=$bar" );
                  if ($response == $checkVal)
                  .
                  .
                  .
                  ?>[/php]And this works very nicely, thank you! However, I am concerned about the contents of the variables, they are originally part of user input, so I put them through urlencode() first, which I'd rather not do. Is there any way I can put these variables into a POST action and get back the results with code that is as simple (or as close to as simple) as the above snippet???

                  Thanks so much for your help.

                  Comment

                  • iam_clint
                    Recognized Expert Top Contributor
                    • Jul 2006
                    • 1207

                    #10
                    your mistaking my post ronverdonk you can have javascripts submit the form using POST method which would in turn not put it in the address thanks have a good day.

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      Okay iam_clint, you are right. It is just that I don't really like JavaScript or any other client-side routines.

                      Ronald :cool:

                      Comment

                      • iam_clint
                        Recognized Expert Top Contributor
                        • Jul 2006
                        • 1207

                        #12
                        :) i am a javascript whore..

                        Comment

                        • RonS
                          New Member
                          • Sep 2006
                          • 4

                          #13
                          Originally posted by RonS
                          Is there any way I can put these variables into a POST action and get back the results with code that is as simple (or as close to as simple) as the above snippet???
                          Anybody have a clue on how to help me accomplish my goal?

                          I need to get back a response from the second server. File_get_conten ts() handles that quite nicely for me, and of course allows me to pass the variables in a GET action.

                          Any code or functions that someone can steer me towards that would be almost as elegant as file_get_conten ts, allow me to read the page returned, yet allow me to use the POST method?

                          Thanks again in advance.

                          Comment

                          • ronverdonk
                            Recognized Expert Specialist
                            • Jul 2006
                            • 4259

                            #14
                            Ron S: I'll have to route you to a link to a 5-page tutorial that explains using CURL to query remote servers http://www.higherpass.com/php/tutori...ote-Servers/1/

                            Ronald :cool:

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              Originally posted by iam_clint
                              :) i am a javascript whore..
                              Iam_clint: now you've made me curious. Could you show me a link that explains using JS to POST data? Thanks.

                              Ronald :cool:

                              Comment

                              Working...