Link to home
Start Free TrialLog in
Avatar of gothamww
gothamww

asked on

curl post form and redirect

Hi:

I'm posting a form to authorize.net for credit card payment.  I'd like to save some of the post variables in my own database before sending the form fields off to authorize.net, so I'm posting the form to my server, storing the variables I need to, and then trying to programmatically post the form.  It looks like I ought to be able to use cURL to do this, but I'm having trouble getting it to work the way I'd like it to.

I'm using this code:

     // store my own form values on my server here...
    ....some code to do that goes here....

    /// now post the form to authorize.net as if I hadn't intercepted it

      $aQueryStrs = array();
      foreach ($_POST as $key => $value) {
            $value = urlencode(stripslashes($value));
            $aQueryStrs[] .= "$key=$value";
      }
      $query_string = implode('&',$aQueryStrs);

      $Curl_Session = curl_init("https://secure.authorize.net/gateway/transact.dll");
      curl_setopt ($Curl_Session, CURLOPT_POST, 1);
      curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, $query_string);
      curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
      curl_exec ($Curl_Session);
      curl_close ($Curl_Session);

This posts the form and returns the HTML to my server.  What I'd really like to do is post the form and end up on authorize.net's server.   Without knowing too much about cURL it would seem that setting the FOLLOWLOCATION option to 1 would do this, but it doesn't.  The resulting HTML is returned to my server and the browser stays there - it doesn't redirect.  How can I post the form and redirect to authorize.net at the same time?

-Charlie
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gothamww
gothamww

ASKER

works very well, thanks.