cURL nichts zurück

cURL gibt nichts zurück, wenn auf dem server. Alles funktioniert auf localhost, aber wenn es im remote-hosting-getSearchResults() gibt nichts (oder 302-header). Ist das etwas, was falsch mit der server-Konfiguration (habe versucht, 2 verschiedene). Kann es sein, etwas mit CURLOPT_FOLLOWLOCATION? Versucht, sowohl die wahren und falschen auf localhost - funktioniert immer noch. Auf remote-hosting-es ist nicht erlaubt, zu Folgen, Standort für einige Grund, aber wenn es funktioniert, ohne auf lokale ich denke nicht, dass das zählt.

<?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;
    }
}
?>
  • Ich habe noch nie gehört, von einem bestimmten cURL-option deaktiviert hosting so. Kontaktieren Sie Ihren host oder switch.
  • es ist nicht curl-option deaktiviert FOLLOWLOCATION ist deaktiviert, wenn PHP läuft im safe mode.
  • Freundliche Erinnerung! Bitte verwenden Sie protected statt private. Es erlaubt die Erweiterbarkeit und unit-tests später und wird als gute Praxis.
  • Ich würde sagen, dass deaktiviert. Sie sollten wirklich ein host ohne den abgesicherten Modus, wird Ihr Leben viel einfacher. Es ist so nutzlos Sie haben deprecated in PHP 5.3 umgestellt. php.net/manual/en/features.safe-mode.php
InformationsquelleAutor heroix | 2012-01-20
Schreibe einen Kommentar