C
C
carry-y2015-12-09 01:16:21
PHP
carry-y, 2015-12-09 01:16:21

PHP cURL entering data into a form and viewing the result?

I need to get data in my admin panel without going to the track tracking site.
Haven't worked with cURL before, any help would be greatly appreciated.

$URL='https://www.msc.com/blr/help-centre/tools/track-a-shipment';
$data = array();
$data['ctl00$ctl00$plcMain$plcMain$TrackSearch$txtBolSearch$TextField']='MSCU8386787';
$post_str = '';
foreach ($data as $key=>$value){
  $post_str .= $key.'='.urlencode($value).'&';
}
$post_str = substr($post_str,0,-1);



$ch = curl_init(); 
$cookie_jar = tempnam ($_SERVER['DOCUMENT_ROOT'], "cookie.txt");
curl_setopt($ch, CURLOPT_URL,$URL); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($ch, CURLOPT_POST,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_str);  
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE); 
$result=curl_exec ($ch);
curl_close ($ch);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MetaDone, 2015-12-09
@MetaDone

$host = "http://example.com/send";
$cookie = "key=value;";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, "ya.ru");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("key1" => "value1","key2"=>"value2")));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");  

$r = curl_exec($ch);
curl_close($ch);
echo $r;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question