<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);



ini_set('memory_limit', '2048M');
// parametry requestu
$data  = array('client'             => '00139726', 
                'login'             => 'samanta', 
                'pass'              => 'n3PPXWDp8Dg', 
                'req'               => 'params2', 
                'withdesc'                  => 1,
                'ignore_missing'    => '1'
               // 'pid'               => 'UKMIC290015;AKASS113043;KOTRAZT9008;121650;121974;HZBOSPE6750S100', 
            //    'pid'               => '',
              //  'withdesc'          => '1', 
               // 'ignore_missing'    => '1'
               );

// wykonujemy request
$url        = 'https://xml.ab.pl/gateway.php';
$curl       = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$result     = curl_exec($curl);
$err        = curl_error($curl);
$errno      = intval(curl_errno($curl));
curl_close($curl);

// sprawdzamy odpowiedz
if (!$err) {
    
    file_put_contents('params2.xml', $result);
    
    /*$xml = simplexml_load_string($result, "SimpleXMLElement", LIBXML_NOCDATA);
    $json = json_encode($xml);
    $array = json_decode($json,TRUE);
    print_r($array);
    //echo count($array['gateway']['products']);
    exit;*/
    
    // odpowiedz ok, request mozna parsowac
    print(htmlspecialchars($result));
} else {
    // problem CURLa z wykonaniem requestu
    var_dump($err, $errno);
}
