help with php5 and cURL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mickey

    help with php5 and cURL


    I am trying to post an array using cURL from one PHP page to another. I
    can't figure out how to correctly post and read the array on the page
    that actually receives it. Here is what I have...

    $session = curl_init();

    curl_setopt( $session, CURLOPT_URL,
    "https://www.myswebsite. com/receiving.php" );
    curl_setopt( $session, CURLOPT_HEADER, false );
    curl_setopt( $session, CURLOPT_POST, true );
    curl_setopt( $session, CURLOPT_POSTFIE LDS, $_POST['fields'] );
    curl_setopt( $session, CURLOPT_RETURNT RANSFER, true );
    curl_setopt( $session, CURLOPT_SSL_VER IFYPEER, false );
    curl_setopt( $session, CURLOPT_USERPWD , $sslpassword );
    curl_setopt( $session, CURLOPT_HTTPAUT H, CURLAUTH_BASIC );

    $returned = curl_exec( $session );
    curl_close( $session );
    echo $returned;

    On the receiving page this echos zero ...

    $numFormFields = count( $_POST['fields'] );
  • Andy Jeffries

    #2
    Re: help with php5 and cURL


    Hi Mickey,

    Two things:

    1) Check that you've got the syntax of this right:
    [color=blue]
    > curl_setopt( $session, CURLOPT_POSTFIE LDS, $_POST['fields'] );[/color]

    If $_POST['fields'] currently contains an array, you probably want to do
    something like this:

    curl_setopt( $session, CURLOPT_POSTFIE LDS,
    array("fields"= >$_POST['fields']));

    Otherwise you aren't passing through a name the array can be referred to
    using on the other side.

    2) I don't know how PHP will handle you trying to pass an array (PHP
    data structure) over HTTP. You may need to use the serialize/unserialize
    functions on the data on the way in/out (respectively).

    Cheers,


    Andy


    --
    Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
    http://www.gphpedit.org | PHP editor for Gnome 2
    http://www.andyjeffries.co.uk | Personal site and photos

    Comment

    Working...