php - curl_exec returns empty string -


i'm still bit new using curl pull data , i've started using fiddler find options need set.

i'm trying see if can pull image site. first hit search page - set search parameters, start hitting links in results. when attempt go link in 1 of results image, empty string returned curl_exec().

the weird thing - @ 1 point, worked - got data , saved image locally. stopped, , have no idea doing have working. naturally, works ok in browser. :(

i'm using simple html dom parse through results , curl actual page requests. curl_error() not show error, curl_getinfo() thinks ok too. it's trivial, i'm not sure how troubleshoot beyond am.

<?php include 'includes/simple_html_dom.php';  $url = "http://nwweb.co.bell.tx.us/newworld.aegis.webportal/corrections/inmateinquiry.aspx";  // cookie - asp.net_sessionid $ch = curl_init($url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 1); $r = curl_exec($ch); preg_match_all('/^set-cookie:\s*([^;]*)/mi', $r, $matches); $cookies = array(); foreach($matches[1] $item) {     parse_str($item, $cookie);     $cookies = array_merge($cookies, $cookie); } $sessioncookie = "asp_net_sessionid=".$cookies['asp_net_sessionid'];  // load page simple html dom , inputs - ignore buttons , populate our dates $startdate = "02%2f01%2f2000"; $enddate = "02%2f07%2f2016";  $getinputs = str_get_html($r); $inputs = $getinputs->find('input');  $inputs_array = array(); $buttons_array = array();  ($i=0; $i<count($inputs); $i++) {     if ($inputs[$i]->type != "submit")     {         $inputs_array[$inputs[$i]->id] = $inputs[$i]->value;         if (stripos($inputs[$i]->id, "fromdate") > 0)             $inputs_array[$inputs[$i]->id] = $startdate;         if (stripos($inputs[$i]->id, "todate") > 0)             $inputs_array[$inputs[$i]->id] = $enddate;     } }  // build our curl data - includes hidden inputs, our & dates, plus search button $curl_data = http_build_query($inputs_array)."&ctl00%24defaultcontent%24uxsearch=search";   // post data, include session cookie $ch = curl_init($url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $curl_data); curl_setopt($ch, curlopt_cookie, $sessioncookie); $response = curl_exec($ch);  // shows can data // find links html  $htmldom = str_get_html($response); // load simple html dom // table of results $divtable = $htmldom->find('div#ctl00_defaultcontent_uxresultswrapper',0)->find('table',0); $rows = $divtable->find('tr'); ($i=1; $i<count($rows);$i++) {     if ($i>3) break; // limit length of script debugging     $link = $rows[$i]->find('td',1)->find('a',0)->href;      // build query inmate details link above     $url = "http://nwweb.co.bell.tx.us/newworld.aegis.webportal/corrections/".$link;     $ch = curl_init($url);     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_header, 1);     curl_setopt($ch, curlopt_cookie, $sessioncookie);     $page = curl_exec($ch);     $pagedata = str_get_html($page);      // find photo, there's thumb in div.bookingphotos     // linked full size image, link of form http://nwweb.co.bell.tx.us/newworld.aegis.webportal/getimage.aspx?imagekey=17c030is, in href, has ../getimage.aspx?imagekey=xxxx     $photolink = $pagedata->find('div.bookingphotos',0)->find('a',0)->href;     // rid of .. , put base url on front     $imglink = str_replace("..", "http://nwweb.co.bell.tx.us/newworld.aegis.webportal", $photolink);      // attempt pull image     $ch = curl_init($imglink);     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_header, 1);     curl_setopt($ch, curlopt_cookie, $sessioncookie);      // here problem - no data returned     $imgdata = curl_exec($ch); // header back, no data } ?> 


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -