help with php5 and cURL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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,  
" " );
curl_setopt( $session, CURLOPT_HEADER, false );
curl_setopt( $session, CURLOPT_POST, true );
curl_setopt( $session, CURLOPT_POSTFIELDS, $_POST['fields'] );
curl_setopt( $session, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $session, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $session, CURLOPT_USERPWD, $sslpassword );
curl_setopt( $session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );

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

On the receiving page this echos zero ...

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

Re: help with php5 and cURL

Hi Mickey,

Two things:

1) Check that you've got the syntax of this right:

Quoted text here. Click to load it

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

curl_setopt( $session, CURLOPT_POSTFIELDS,

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).



Andy Jeffries MBCS CITP ZCE   | gPHPEdit Lead Developer | PHP editor for Gnome 2 | Personal site and photos

Site Timeline