I have a Joomla controller that iterates a number of times over some Google Checkout XML code. What I want is during this iteration, POST data to another page - in the same site.
so
com_mycomponent/controllers/checkout_iterator.php //breaks up the xml into small parts and posts then to the executor, one at a time
com_mycomponent/controller开发者_如何学JAVAs/checkout_executor.php //does the real work for each XML element it is passed
The iterator.php controller will POST data to executor.php maybe 2 or even 50 times.
How can I do this?
To post data to a page in php, you can use the cURL extension
A quick and dirty way may be like this..
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'com_mycomponent/controllers/checkout_executor.php');
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_POST, true);
// send data
curl_setopt($c, CURLOPT_POSTFIELDS, 'a=1&b=2..');
curl_exec($c);
// other data.. we can use same handle
curl_setopt($c, CURLOPT_POSTFIELDS, 'a=1&b=2..');
curl_exec($c);
// don't forget to close
curl_close($c);
精彩评论