Когда я запускаю curl, я получаю статус 0 - PullRequest
0 голосов
/ 19 сентября 2011

Я использую этот код для получения страницы из интернета ... но я получаю статус результата 0

$url='http://www.jiwlp.com';

$this->url = $url;

if (isset($this->url)) {

    // start cURL instance 
    $this->ch = curl_init ();

    // this tells cUrl to return the data
    curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, 1);

    // set the url to download 
    curl_setopt ($this->ch, CURLOPT_URL, $this->url); 

    // follow redirects if any 
    curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION, true); 

    // tell cURL if the data is binary data or not 
    curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, $this->binary); 

    $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

    curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($this->ch, CURLOPT_VERBOSE, 1);  
    curl_setopt($this->ch, CURLOPT_USERAGENT, $useragent); 
    curl_setopt($this->ch, CURLOPT_TIMEOUT, 5);

    // grabs the webpage from the internet 
    $this->html = curl_exec($this->ch);
    $this->status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

    print_r(curl_getinfo($this->ch)); // closes the connection
    curl_close ($this->ch);
}

Может кто-нибудь объяснить, что я делаю неправильно.

Спасибо

Ответы [ 4 ]

0 голосов
/ 05 февраля 2014

проверка CURL в отключенной функции php.

, если CURL_EXEC отключен на веб-сервере, php вместо этого не выдаст ошибку [http_code] => 0 header_size] => 0 .......

запустит phpinfo () изСтраница php - это один из способов получить список отключенных функций php.

0 голосов
/ 19 сентября 2011

у меня эта версия работает, убрал oo

$url = 'http://www.jiwlp.com';

if(isset($url)){
$ch = curl_init();
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch,CURLOPT_BINARYTRANSFER,$binary);

    $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
 rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true);
    curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
    curl_setopt($ch,CURLOPT_VERBOSE,1);
    curl_setopt($ch,CURLOPT_USERAGENT,$useragent);
    curl_setopt($ch,CURLOPT_TIMEOUT,5);
    curl_exec($ch);
    $status = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    print_r(curl_getinfo($ch));
    curl_close($ch);
}
0 голосов
/ 26 марта 2013

я использую эту функцию, чтобы получить http сайт / статус ссылки:

<?php
function get_link_status($url, $timeout = 10) 
{
$ch = curl_init();
// set cURL options
$opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
            CURLOPT_URL => $url,            // set URL
            CURLOPT_NOBODY => true,         // do a HEAD request only
            CURLOPT_TIMEOUT => $timeout);   // set timeout
curl_setopt_array($ch, $opts);
curl_exec($ch); // do it!
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // find HTTP status
curl_close($ch); // close handle
echo $status; //or return $status;
    //example of check
    if ($status == '301') { echo 'This is redirected';}
}

get_link_status('http://site.com');
?>
0 голосов
/ 19 сентября 2011

Статус ответа уже сохранен в $this->status, я предполагаю, что вы имеете в виду коды состояния ответа HTTP, поэтому вместо

// grabs the webpage from the internet 
$this->html = curl_exec($this->ch);  
$this->status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

print_r(curl_getinfo($this->ch));

Попробуйте вместо этого напечатать $this->status.

// grabs the webpage from the internet 
$this->html = curl_exec($this->ch);  
$this->status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

print_r($this->status);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...