SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: Processing a POST-type form through header() ?

  1. #1
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Processing a POST-type form through header() ?

    Is it possible to do this:

    PHP Code:
    header("Location: submit.php?&userid=4"); 
    But act as if it were a FORM being processed with the POST type.

    So, identical as if <form action="submit.php"> and <input type="hidden" name="user" value="4" /> were being processed.

    And when I am redirected to the new page, the URL in the address bar should be clean, and show only submit.php (not act like a GET).

    Hopefully this makes some sense..

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I just had a play but with no luck. You'd need to send some HTTP headers around. I've attached a simple EXE (zipped) that will probably help, it reads headers from page requests, pretty nifty tool
    Attached Files

  3. #3
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm.. I think you forgot to attach it.

  4. #4
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a great article over at http://www.zend.com/zend/spotlight/mimocsumissions.php

    Should help you out :-)
    My name is Steve, and I'm a super-villian.

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hrrrmmmm, I'm sure I attached it

  6. #6
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Attachments have to be approved by an Advisor.
    Mike
    It's not who I am underneath, but what I do that defines me.

  7. #7
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ta

  8. #8
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lieut_data
    There's a great article over at http://www.zend.com/zend/spotlight/mimocsumissions.php

    Should help you out :-)
    Thanks lieut, that tutorial is very thorough, although not quite what I need.

    Everything is there, but in that tutorial when the POST data is processed, it doesn't actually take you to the new URL.

    My example is that once a customer to my website fills out the "pay" form and clicks "pay via paypal," I need to pass POST data using header(), or sockets, into PayPal.

    I need it to redirect to that PayPal page also, where you actually buy the product.

    I see it is if I used this code, it will process the data via socket, but it wont redirect to the PayPal page... or at least that is what I think it'll do.

    Using the structure of the data from that nifty program P@ckman posted, would something like this work?
    PHP Code:
    header("POST /cgi-bin/webscr HTTP/1.0");
    header("Host: WWW.PAYPAL.COM");
    header("Content-Type: application/x-www-form-urlencoded");
    header("amount=$amount&business=$business,etc.....");
    header("Location: /cgi-bin/webscr"); 
    Or is this idea just totally wack?

    Currently I use the following:

    PHP Code:
    <?php

    //php verify stuff
    //I check whether the user is paying via credit-card with 2checkout, or paypal. If paypal, I do the following:

            
    echo '<html>
            <head><title>Verifying..</title></head>
            <body onload="document.paypal.submit();">

            <form name="paypal" method="POST" action="https://www.paypal.com/cgi-bin/webscr">
            <input type="hidden" name="cmd" value="'
    .$cmd.'" />
            <input type="hidden" name="amount" value="'
    .$total.'" />
            <input type="hidden" name="item_name" value="'
    .$item_name.'" />
            <input type="hidden" name="item_number" value="'
    .$user_key.'" />
            <input type="hidden" name="business" value="'
    .$business.'" />
            </form>

            </body>
            </html>'
    ;

    ?>
    The only problem with this is that if the user is at the PayPal page, and clicks the browser back button, then will get sent to this "temp" page, and then redirected back to PayPal. So they've gotta click back twice and fast.

    Also I would guess if they had javascript disabled, then the "onload" behavior would be utterly useless.

    Help

  9. #9
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure this is going to be quite possible, as you would have to force the browser to POST to the PayPal website..

    However, after reading http://forums.devshed.com/t15245/s.html, I came across a bright idea -- simply change the nature of your current page to show a "Are these values correct?", after which the user checks over their input, clicks "Yes", and you sneakily POST to the right page (the inner page does the checking you want it do :-), storing hidden results as you currently do).
    My name is Steve, and I'm a super-villian.

  10. #10
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pretty crafty, Lieut.

    Even though all the serious confirmation gets done on the Paypal page (making it one more page the user has to click through), it gets the job done.

    Thanks

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    1,932
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Hey guys,

    Has anyone come up with anything usefull to achieve this?

    I am doing exactly the same thing as Solace D. and have gone through almost all the same hoops. Slightly different method to post the page with JavaScript but basically the same exact thing.

    I looped out my posted variables on the transitional page into hidden fields and also include a "continue transaction" submit button just in case.

    I went to PHP Builder and looked at some code in the snippet library http://phpbuilder.net/snippet/browse.php?by=cat&cat=9 but still no luck. It probably does the same as the methods discussed here.

    I'll still continue but it looks like a confirmation page is the only solution for the moment.

    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  12. #12
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    1,932
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    A little update.

    I received a link from a friend just a short while ago that may provide some success.

    I'm stepping away from the computer for a while and I'll try a little later, but here it is if someone wants to have another kick at it:
    http://www.alt-php-faq.com/local/55
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  13. #13
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    1,932
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I've been pulling my hair out on this one for the last couple of days and have an update that might come in handy in the future.

    I managed to get the curls code to work however I was not able to make good use of it and will more than likely use PayPal Instant Payment Notification (IPN) to post back a confirmation of successful sale and customer information so that I can send of a branded "thank you" message.

    For what it's worth here is the PHP curl() code that actually worked:
    PHP Code:
     
    <?php

        
    iF($_SERVER['REQUEST_METHOD'] == "POST"){

    $myVariables 'cs=0'//Sets page bg color

    foreach( $HTTP_POST_VARS as $key=>$value ) { 

    $myVariables .= "&$key=$value";
    }

    $myCurl curl_init();
    curl_setopt($myCurlCURLOPT_URL,"https://www.paypal.com/cgi-bin/webscr"); 
    curl_setopt($myCurlCURLOPT_POST1); 
    curl_setopt($myCurlCURLOPT_POSTFIELDS$myVariables);
    curl_exec ($myCurl);
    curl_close ($myCurl);

        } else {


    header("Location: index.php"); 

        }


    ?>
    It grabs the posted values and posts them to PayPal. The browser is somewhere between Paypal and your domain so the page shows most of the information however it needs some work.

    Maybe this will help out someone else in the future.
    See ya,
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  14. #14
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you checked out snoopy , I think it does https with CURL

Bookmarks

Posting Permissions

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