cURL은 서버에있을 때 아무 것도 반환하지 않습니다. 모든 것이 localhost에서 잘 작동하지만 원격 호스트에있을 때 getSearchResults()는 아무것도 반환하지 않습니다 (또는 302 헤더). 서버 구성에 문제가 있습니까 (2 가지 시도). CURLOPT_FOLLOWLOCATION이 (가) 뭔가있을 수 있습니까? 로컬 호스트에서 true와 false 모두 시도 - 여전히 작동합니다. 원격 호스팅에서 어떤 이유로 든 위치를 추적 할 수는 없지만, 지역에없는 경우에는 문제가 없다고 생각합니다.cURL은 아무 것도 반환하지 않습니다.
<?php
class cURL
{
private $username;
private $password;
private static $tmpfname;
public function __construct($username,$password) {
$this->username = $username;
$this->password = $password;
$this->makeCookies($username, $password);
}
private function makeCookies($username, $password) {
self::$tmpfname = tempnam("/tmp", "Cookie");
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEFILE, self::$tmpfname);
curl_setopt($ch, CURLOPT_COOKIEJAR, self::$tmpfname);
curl_setopt($ch, CURLOPT_URL,"http://vk.com/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "email={$username}&pass={$password}");
ob_start();
curl_exec($ch);
ob_end_clean();
curl_close($ch);
unset($ch);
}
private function getHTML($url){
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEFILE, self::$tmpfname);
curl_setopt($ch, CURLOPT_COOKIEJAR, self::$tmpfname);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
public function getSearchResults($songname) {
$songname = urlencode($songname);
$contents = $this->getHTML("http://vk.com/search?c[section]=audio&c[q]={$songname}");
return $contents;
}
}
?>
이와 같은 호스팅에서 특정 cURL 옵션이 비활성화 된 것을 들어 본 적이 없습니다. 호스트 또는 스위치에 문의하십시오. – ceejayoz
@ceejayoz curl 옵션이 비활성화되어 있지 않습니다. PHP가 안전 모드로 실행되면'FOLLOWLOCATION'이 비활성화됩니다. – Ranty
@heroix 친절한 알림! 개인 대신에 보호 된 것을 사용하십시오. 나중에 확장 성 및 단위 테스트를 허용하며 이는 우수 사례로 간주됩니다. –