0

I've googled a lot right now and just can not find the answer.

I have a PHP that logs in to a site and downloads a pdf file using cURL. This is my code:

<?php
require ("test_pass.php");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://rapid.deltion.nl/user/login/');
curl_setopt($ch,     CURLOPT_POSTFIELDS,'username='.urlencode($login_email).'&password='.urlencode($l    ogin_pass).'&login=Login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/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_setopt($ch, CURLOPT_REFERER, "https://rapid.deltion.nl/student/info/");
$page = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL,     'https://rapid.deltion.nl/student/pdfresultaten/id/97041344/Luuk%20Wuijster.pdf'    );
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
$Result = curl_exec($ch);

header('Cache-Control: public');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="cijferlijst.pdf"');
header('Content-Length: '.strlen($Result));
echo $Result;

eventually I want to run this code every hour with a cronjob and compare the pdf with the pdf it downloaded one hour ago.

The problem is that it downloads the pdf to my own computer when I go to the url. So I tried to run the script from my server but that didn't work either.

halfer
  • 19,824
  • 17
  • 99
  • 186
Luuk Wuijster
  • 6,678
  • 8
  • 30
  • 58
  • As the URLs contains HTTPS schema, does the server have a certificate bundle? See [this question](http://stackoverflow.com/questions/731117/error-using-php-curl-with-ssl-certificates) for more information. – Jirka Hrazdil Dec 08 '16 at 12:51
  • You need to store `$Result` instead of outputting it to the browser. – jeroen Dec 08 '16 at 12:51
  • 1
    Well, you _output_ the content to the requesting client, so the browser, "your computer". Don't do that, but save the content into a file instead using phps file management functions. – arkascha Dec 08 '16 at 12:53

0 Answers0