Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
$url2 = 'http://www.website.com/b2b/handleinvoicedownload.php';
$fields = array(
'delim'=>urlencode('csv'),
'headerRow'=>urlencode('0'),
'startDate'=>urlencode('01/01/2015'),
'endDate'=>urlencode('01/26/2015'),
'columndata[1]'=>urlencode('orn'),
'columndata[2]'=>urlencode('ord'),
'columndata[3]'=>urlencode('sub'),
'columndata[4]'=>urlencode('shc'),
'columndata[5]'=>urlencode('tot'),
'columndata[6]'=>urlencode('svc'),
'columndata[7]'=>urlencode('svn'),
'columndata[8]'=>urlencode('svs'),
'columndata[9]'=>urlencode('pon'),
'columndata[10]'=>urlencode('trc'),
'columndata[11]'=>urlencode('shd'),
'columndata[12]'=>urlencode('inv'),
'columndata[13]'=>urlencode('td'),
'columndata[14]'=>urlencode('null'),
'columndata[15]'=>urlencode('null'),
'save'=>urlencode('0'),
'sumbit.x'=>urlencode('38'),
'sumbit.y'=>urlencode('16')
);
//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,7);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.website.com/b2b/handleinvoicedownload.php');
curl_setopt($ch, CURLOPT_URL,$url2); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 50); // times out after 50s
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
echo $buffer2 = curl_exec($ch); // run the whole process
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
exit;
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.