470,833 Members | 1,346 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

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_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
1 1423

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,
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

Apr 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jason Morehouse | last post: by
4 posts views Thread by Daniel Andersen | last post: by
13 posts views Thread by Gary Quiring | last post: by
5 posts views Thread by voronwae | last post: by
3 posts views Thread by Chuck Renner | last post: by
1 post views Thread by Skeleton Man | last post: by
1 post views Thread by devranger | last post: by
1 post views Thread by c1pkw | last post: by
3 posts views Thread by k.rollman | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.