Problem med curl.
Hejsa,Jeg sidder og laver et script, som logger ind på en side, og derefter henter en dynamisk genereret xls (excel) fil.
Dog har jeg lidt problemer.
Den logger fint nok ind (selve det stykke, er taget fra et tidligere script lavet til samme side, som bare udskrev noget kildekode fra den side - det virkede fint), men den gemmer ikke xls filen.
Er der nogen der kan tjekke igennem, og se om jeg gør noget galt?
<?PHP
$login_user = 'xxxx';
$login_pass = 'xxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://xxxx.xxxxxxxx.dk/partnersystem/mylogins.php');
curl_setopt($ch, CURLOPT_POSTFIELDS,'username='.urlencode($login_user).'&password='.urlencode($login_pass).'&send=Send');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);
$fp = fopen ('stat.xls', 'w+');
$ch = curl_init("http://http://xxxx.xxxxxxxx.dk/partnersystem/xxxx_stats.php?from_date=2008-09-20&to_date=2008-09-30");
curl_setopt($ch, CURLOPT_POSTFIELDS,'username='.urlencode($login_user).'&password='.urlencode($login_pass).'&send=Send');
curl_setopt($ch, CURLOPT_REFERER, 'http://http://xxxx.xxxxxxxx.dk/partnersystem/statistic.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_exec($ch);
?>
Hvis jeg ville hente filen manuelt ville jeg gøre følgende:
1) Logge ind på siden
2) Gå til statistics.php
3) Trykke på knappen "download data", som kører et javascript med window.location='http://http://xxxx.xxxxxxxx.dk/partnersystem/xxxx_stats.php?from_date=2008-09-20&to_date=2008-09-30'
På forhånd tak.
