Ne bir https:// URL'den veri almak için benim PHP / CURL kodu değiştirmek zorunda mı?

0 Cevap php

Ben bir parametre olarak, daha sonra plain text Google Doc döndürür CURL bir Google Doc URL kabul kullanarak PHP dosyası var.

Görünüşe göre bir redirect ilave edildiğinde yakın zamana kadar iyi çalıştı, böylece http:// address redirects to the equivalent https:// adresi, bu örnekte olduğu gibi:

http://docs.google.com/View?id=dc7gj86r_20dn2csqg3

Yani https:// address, but it just returns blank erişmek için kodumu değiştirdi.

What do I have to change my CURL code so that I can get the HTML text from the https:// address?

$url = filter_input(INPUT_GET, 'url',FILTER_SANITIZE_STRING);

$validUrlPrefixes[] = "https://docs.google.com";

if(beginsWithOneOfThese($url, $validUrlPrefixes)) {
  $user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
  curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie");
  curl_setopt($ch, CURLOPT_URL, $url ); 
  curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
  curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);

  $rawData = curl_exec($ch);  

  $rawData = cleanText($rawData);

  if(beginsWith($url, "https://docs.google.com")) {
    echo qstr::convertGoogleDocContentToText($rawData);
    die;
  }

  echo $rawData;
  die;

0 Cevap