Php 如何将数组添加到url或发送post数组?

Php 如何将数组添加到url或发送post数组?,php,session,post,curl,Php,Session,Post,Curl,好的,我有一个卷发的要求,我正在尝试 $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

好的,我有一个卷发的要求,我正在尝试

$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;
内容或
$\u会话['cart']

Array
(
  [155] => 1
  [78] => 1
)
我需要将此数据作为post数据或get变量发送…有什么建议吗

论捕捉功能

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'));
}
public function ajax\u get\u all\u products(){
$this->language->load('module/cart');
$all_products=$this->cart->getProducts();
$data\u returned=json\u encode($all\u产品);
echo“”。打印请求($请求,true)。“”;
回显“.print\u r($\u POST,true)。”;
$this->response->setOutput($data\u returned,$this->config->get($config\u compression));
}
我没有得到我设置的阵列。这两个文件在同一台服务器上。顺便说一句,请尝试:

$post = "";
   $amp = "";
   foreach($_SESSION['cart'] as $key => $value) {
       $post .= $amp . $key . "=" . urlencode($value);
       $amp = "&";                        
   }
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
试试这个:

试试这个


尝试使用php序列化和非序列化函数


您的cURL脚本文件中是否有session\u start()?是的,我有session\u set\u cookie\u参数(0,“/”);会话_start();所以我尝试了curl_setopt($ch,CURLOPT_POSTFIELDS,array('items'=>introde(“,”,$”会话['cart'));但是它只返回[items]=>1,1,这是我需要的一半
$post_data = http_build_query(array('items' => $_SESSION['cart']));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$post = "";
   $amp = "";
   foreach($_SESSION['cart'] as $key => $value) {
       $post .= $amp . $key . "=" . urlencode($value);
       $amp = "&";                        
   }
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);