note 59993 added to function.curl-setopt

From: Date: Thu, 22 Dec 2005 10:13:31 +0000
Subject: note 59993 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-100563@lists.php.net to get a copy of this message
There is really a problem of transmitting $_POST data with curl in php 4+ at least. I improved the encoding function by Alejandro Moreno to work properly with mulltidimensional arrays. <?php function data_encode($data, $keyprefix = "", $keypostfix = "") { assert( is_array($data) ); $vars=null; foreach($data as $key=>$value) { if(is_array($value)) $vars .= data_encode($value, $keyprefix.$key.$keypostfix.urlencode("["), urlencode("]")); else $vars .= $keyprefix.$key.$keypostfix."=".urlencode($value)."&"; } return $vars; } curl_setopt($ch, CURLOPT_POSTFIELDS, substr(data_encode($_POST), 0, -1) ); ?> ---- Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59993 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59993&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59993&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100563) next »