1

Possible Duplicate:
Passing $_POST values with cURL

I am trying to use curl to pass on $_POST values sent from a form to a itermediary verification page, on to another server for processing ...and then back ot our server to display success page.

Here is what I have:

    unset($_POST['recaptcha_challenge_field']);
    unset($_POST['recaptcha_response_field']);
    $params = $_POST;
    foreach ( $params as $key => $value) {
      $post_items[] = $key . '=' . $value;
    }
    $post_string = implode ('&', $post_items);
    $curl_connection =
    curl_init('http://server.somedomain.net/about/spit.php');
    curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($curl_connection, CURLOPT_USERAGENT,
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
    $result = curl_exec($curl_connection);
    print_r(curl_getinfo($curl_connection));
    echo curl_errno($curl_connection) . '-' .
    curl_error($curl_connection);
    //close the connection
    curl_close($curl_connection);

The data seems to be there and in the correct format but it does not send out to the server, as far as I can tell. Any idea what is wrong with this? I am a bit baffled.

Dave

Community
  • 1
  • 1
Dave
  • 59
  • 3
  • 12

1 Answers1

1

You forgot:

curl_setopt($curl_connection, CURLOPT_POST, 1);

And change:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);

to

curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, false);

in PHP 5.2+ POSTFIELDS must be an Array!

http://php.net/manual/en/function.curl-setopt.php#example-4025

Zemistr
  • 1,049
  • 7
  • 10
  • I see this has been closed and I have looked at the examples that were deemed duplicates but I truthfully do not see how they are. I am trying to capture post values from a form on another page, run validation of a captcha and if that passes, forward the post values on to another external server, which processes the data, sends out confirmation emails and then returns the user to the original server to show a success page. I don't think that is what is being discussed in the so-called duplicate posts. I could be wrong through? – Dave Dec 13 '12 at 17:06
  • Of course...everything is possible :D But why? – Zemistr Dec 13 '12 at 22:27