Hi, I need what is probably a simple piece of information....

I'm setting up a payment gateway for a client and their prebuilt scripts are Perl, which I don't usually use.

However, I'm not familiar with cognate functions in PHP.... I can supply code samples from the Perl script if needed, but I think this is probably pretty straightforward....

I need to know how to send form data to the 3rd party server and read it's response code as a variable which can then be interpreted by my local PHP script.

Pseudocode would look something like this:

$form = $HTTP_POST_VARS; 
$response = submitForm($form);

So that $response contains the code regurgitated by the 3rd party servers cgi script. I'm assuming this is straightforward, but I'm having a hard time Googling the proper functions....

    Assuming that the server is probably only accessible using SSL, you can call cURL from PHP:

    exec( "/usr/bin/curl -d \"key=val&key2=val2\" https:\\thesite.com", $returnArray );

    The URL looks funky because this forum trys to make it a link.

      the server is accessable either through standard HTTP or HTTPS... will that make a difference for cURL? We might be using the standard HTTP server until our SSL cert gets activated.

      Additionally, is this something I will need my webhost to install if it isn't already? In other words, is this standard php library code?

        You might be able to get (or even already have) cURL installed. And if it is or can be, compiling the [man]cURL[/man] extension for PHP isn't too far off either. And yes, it can do SSL, provided you have OpenSSL installed (and yes, PHP also has an [man]OpenSSL[/man] extension).

        All in all cURL is a very nice wrapper around what it does; but it should be feasible to write http POSTs yourself and use PHP's own [man]fsockopen[/man] to open a socket, write the POST to it, and then read the response.
        Something like...

        POST https://www.example.com/form.cgi HTTP/1.1
        Host: www.example.com
        User-Agent: PHP automated form poster
        Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,
        Content-Type: application/x-www-form-urlencoded
        Content-Length: 17
        key=val&key2=val2
        

        You will need OpenSSL installed to do https.

          Beware "Transfer-Encoding: chunked" when reading back responses, as if you haven't got a clue what that is (that would have been me, then), and are trying to read back a number it can have you bawling like a baby trying to figure why the script that ran on your test server fine now seems to be cackling at you 'go on, debug me - see if you can!'

            Okay, first of all, thanks to everyone for your help. I'm finally starting to make headway here and my client is getting less and less likely to hang me by the minute.

            However, I have run into this "Transfer-Encoding: chunked" issue already. I'm not sure if it's going to be a problem or not. Most response codes do not contain numbers, but the approval code does. I don't think the number is unique, but I'm just not sure if it's going to matter.

            Any advice on how to deal with this potential problem? I'll go google "Transfer-Encoding: chunked" in the meantime.

            THANKS!!!!!!!!!!!!!

              I've attached a file containing a modified version of the zend thingy, but it also handles chunked encoding if it's present, might be worth you casting an eye over.

                you well and truly rock, Drakla. Thanks!!!

                Love the signature, BTW.. too bad I enjoy making the baby jesus cry...LOL

                  Write a Reply...