By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

help with php5 and cURL

P: n/a

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'] );
Apr 12 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a

Hi Mickey,

Two things:

1) Check that you've got the syntax of this right:
curl_setopt( $session, CURLOPT_POSTFIELDS, $_POST['fields'] );

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

Apr 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.