I do not seem to pick the excel file at the end of the query.
What Am I doing wrong?
Here is what I have so far :
#! /usr/local/bin/php -q
<?php
$url="https://elicensing.iowaabd.com/OnDemandReport.aspx";
$referer="https://elicensing.iowaabd.com";
$header[] = "Content-type: text/html";
$cookie="cookie.txt";
$fp=fopen($cookie,w);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$content=curl_exec($ch);
$array=explode("\n",$content);
$count=count($array);
for($i=0;$i<$count;$i++){
if(stristr($array[$i],"__VIEWSTATE")){
$array1=explode('value="',$array[$i]);
$content1=$array1[1];
$array2=explode('"',$content1);
$content2=$array2[0];
$VIEWSTATE=$content2;
}
}
$VIEWSTATE=urlencode($VIEWSTATE);
$fields = "EVENTTARGET=lnkExcelExport&EVENTARGUMENT=&__VIEWSTATE=$VIEWSTATE";
$url="https://elicensing.iowaabd.com/OnDemandReport.aspx";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
//
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_REFERER,$referer);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//
$content_stage2=curl_exec($ch);
unlink ("result.txt");
$handle = fopen ("result.txt",w);
fwrite ($handle,$content_stage2);
?>