0

I want to load this link. but i get some error. the return http is ok. what is going on here?

HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 
X-Robots-Tag:noindex, nofollow, nosnippet 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Mon, 01 Jan 1990 00:00:00 GMT Date: Wed, 14 Feb 2018 00:25:58 GMT
Content-Security-Policy: script-src 'report-sample' 'nonce-9FVKa6PbBSHhVPp1t9CsQgHFpDA' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval';object-src 'none';base-uri 'self';report-uri https://csp.withgoogle.com/csp/viewer/
X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block Server: GSE 
Set-Cookie: DRIVE_STREAM=UMl4FRnEZmE; Domain=.drive.google.com; Path=/; Secure; HttpOnly Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35" 
Accept-Ranges: none Vary: Accept-Encoding
Transfer-Encoding: chunked

php:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://drive.google.com/file/d/1wn9lQWIipzLYqyuJMzwwUTh3XUSpuokP/view?usp=sharing");
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 1);

$output = curl_exec($ch);

curl_close($ch);

echo $output;
?>
Axel Amthor
  • 10,980
  • 1
  • 25
  • 44

2 Answers2

0

The issue, if I understand correctly that you're thinking the header information is an error, is most likely due to you are requesting the header information with the body with curl_setopt($ch, CURLOPT_HEADER, 1);. Try removing that line and you should get the body output.

If you want header information returned separately, you could try CURLOPT_HEADERFUNCTION instead, please see https://curl.haxx.se/libcurl/c/CURLOPT_HEADER.html

1000Nettles
  • 2,314
  • 3
  • 22
  • 31
  • If i remove i get white page.. how to load the page using cURL? – Bandarbola855 Feb 14 '18 at 00:39
  • If you "view source", you can see that there is content there, it is just mainly Javascript and other stuff. Try a `echo var_dump($output);` to see the full output of cURL here. Google will most likely not let you cURL to download resources from Drive just FYI. – 1000Nettles Feb 14 '18 at 00:40
  • Can it not the cURL act as browser to bridge client? – Bandarbola855 Feb 14 '18 at 00:42
  • You will most likely have to plug into the Google Drive API (see https://stackoverflow.com/a/25033499/823549.) Even if you manage to cURL Google Drive properly, Google will most likely block your script. Facebook loads because you're loading the main page. Google.com loads too. – 1000Nettles Feb 14 '18 at 00:44
0

You need to explicitly retrieve the response body from your curl request. See Can PHP cURL retrieve response headers AND body in a single request?

Axel Amthor
  • 10,980
  • 1
  • 25
  • 44