php - Using curl to get data from a website -


i trying use curl train information http://www.indianrail.gov.in/know_station_code.html .

have following php code :

<?php $fields = array(             'lccp_src_stncode_dis'=>'mangapatnam-+mum',             'lccp_src_stncode'=>'mum',             'lccp_dstn_stncode_dis‌'=>'ambala+city-+ubc',             'lccp_dstn_stncode'=>'ubc',             'lccp_classopt'=>'sl',             'lccp_day'=>'17',             'lccp_month'=>'8',             'currentmonth'=>'7',             'currentdate'=>'17',             'currentyear'=>'2015'         );  $fields_string = '';         //defining empty string foreach($fields $key=>$value) {      $temp = $key.'='.$value.'&';      $fields_string.$temp; } rtrim($fields_string,'&');      //removing last '&' generated string  $curl = curl_init('http://www.indianrail.gov.in/cgi_bin/inet_srcdest_cgi_date.cgi'); curl_setopt($curl,curlopt_post,1); curl_setopt($curl,curlopt_returntransfer,1); curl_setopt($curl,curlopt_postfields,$fields_string);  $result = curl_exec($curl); var_dump($result); ?> 

the problem output on browser window :

boolean false 

i tried using var_dump(curl_error($curl)) , got following output :

string 'empty reply server' (length=23) 

thanks help.

solution :

$fields = array(     'lccp_src_stncode_dis'=>'mangapatnam-+mum',     'lccp_src_stncode'=>'mum',     'lccp_dstn_stncode_dis?'=>'ambala+city-+ubc',     'lccp_dstn_stncode'=>'ubc',     'lccp_classopt'=>'sl',     'lccp_day'=>'17',     'lccp_month'=>'8',     'currentmonth'=>'7',     'currentdate'=>'17',     'currentyear'=>'2015' );  $fields_string = '';         //defining empty string foreach($fields $key=>$value) {      $temp = $key.'='.urlencode($value).'&'; // urlencode     $fields_string.= $temp; // equal sign     } rtrim($fields_string, '&'); $header = array(         'accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',         'accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7',         'accept-language: en-us;q=0.8,en;q=0.6',         'content-type: application/x-www-form-urlencoded'         ); $curl = curl_init('http://www.indianrail.gov.in/cgi_bin/inet_srcdest_cgi_date.cgi'); curl_setopt($curl,curlopt_post,1); curl_setopt($curl,curlopt_returntransfer,1); curl_setopt($curl,curlopt_httpheader,$header); //server require curl_setopt($curl, curlopt_referer, 'http://www.indianrail.gov.in/know_station_code.html'); //server require curl_setopt($curl,curlopt_useragent,'mozilla/5.0 (windows; u; windows nt 6.1; en; rv:1.9.2.13) gecko/20101203 firefox/3.6.13'); //server require curl_setopt($curl,curlopt_postfields,$fields_string);  $result = curl_exec($curl); //close connection curl_close($curl);  echo $result; 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -