Как добавить массив в URL или отправить массив записей? - PullRequest
2 голосов
/ 22 июня 2011

Хорошо, у меня есть запрос на керлинг, который я пытаюсь сделать.

$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
)

Мне нужно отправить эти данные либо как данные публикации, либо как переменную get ... любые предложения

по функции улавливания

<code>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)."
"; echo "
".print_r($_POST, true)."
"; $ this-> response-> setOutput ($ data_returned, $ this-> config-> get ('config_compression')); }

Я не получаю массив, который я установил. Два файла находятся на одном сервере, кстати

Ответы [ 3 ]

3 голосов
/ 22 июня 2011

попробуй:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('items' => $_SESSION['cart']));

попробуй это:

$post_data = http_build_query(array('items' => $_SESSION['cart']));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
0 голосов
/ 22 июня 2011

Попробуйте использовать функцию php serialize и unserialize

http://php.net/manual/en/function.serialize.php

0 голосов
/ 22 июня 2011

Попробуйте это

$post = "";
   $amp = "";
   foreach($_SESSION['cart'] as $key => $value) {
       $post .= $amp . $key . "=" . urlencode($value);
       $amp = "&";                        
   }
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...