Do you have a question? Post it now! No Registration Necessary. Now with pictures!
April 12, 2006, 2:32 pm
rate this thread
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_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 );
On the receiving page this echos zero ...
$numFormFields = count( $_POST['fields'] );
Re: help with php5 and cURL
1) Check that you've got the syntax of this right:
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
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos