简体   繁体   中英

TCPDF I can't get the html from another page like index.php?something=something

I am struggling to create a pdf file with tcpdf from a dynamically generated page.

My problem is that I've got a logging session and when accessing the file it gets only the credentials if you're not logged in.

So my bit for collecting the html is:

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.domain.com/subdir/index.php?something=ref');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$html = curl_exec($curl_handle);
curl_close($curl_handle);

So what I've got after running it, is 'HTTP Error 401: - Unauthorised'.

I hope my explanation makes sense.

Any help will be much appreciated!

I had the same issue while working with PDF using TCPDF where in curl CURLOPT_USERAGENT was TCPDF like below.

curl_setopt($curl_handle, CURLOPT_USERAGENT, 'TCPDF');

I just commented this line and try to generate pdf and it worked.

I know this is not a proper way but it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM