好吧,我有一個捲曲請求,我正在努力。如何將數組添加到URL或發送數組?
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://someurl.com/shop_pos/index.php?route=module/cart/ajax_get_all_products");
// Do a POST
$items =
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_SESSION['cart']);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
內容或$_SESSION['cart']
是
Array
(
[155] => 1
[78] => 1
)
我需要發送這個數據無論是作爲發佈數據或在捕捉功能得到變量...任何建議
public function ajax_get_all_products(){
$this->language->load('module/cart');
$all_products = $this->cart->getProducts();
$data_returned = json_encode($all_products);
echo "<pre>".print_r($_REQUEST, true)."</pre>";
echo "<pre>".print_r($_POST, true)."</pre>";
$this->response->setOutput($data_returned, $this->config->get('config_compression'));
}
我沒有得到我設置的數組。這兩個文件是在同一臺服務器上BTW
你有cURL腳本文件中的session_start()嗎? – kaese
是的,我做session_set_cookie_params(0,'/'); session_start(); – Trace