2011-06-21 104 views
1

我有这个奇妙的PHP类,用于让我登录到cPanel并调用任何我想要的路径。现在它破了:curl没有登录到cPanel

<?php 
class cPanel { 
    var $cPanelUser = ""; 
    var $cPanelPass = ""; 
    var $cPanelDomain = ""; 
    var $cPanelPort = 0; 
    var $cPanelRel = ""; 
    var $cPanelRoot = ""; 

    function cPanel($cPanelDomain, $cPanelPort, $authUser, $authPass) { 
    $this->cPanelDomain = $cPanelDomain; 
    $this->cPanelPort = $cPanelPort; 
    $this->cPanelUser = $authUser; 
    $this->cPanelPass = $authPass; 
    //Root path of cPanel to load pages begining with/

    $this->cPanelRoot = "http".($this->cPanelPort==2083 ? "s" : "")."://".$this->cPanelDomain.":".$this->cPanelPort."/frontend/x3/"; 
    //Relative path of cPanel to load pages not begining with/
    $this->cPanelRel = $this->cPanelRoot.""; 
    } 
    function fetchPage($cPanelPage, $sPostVars = "") { 
    $curl = curl_init(); 
    $loginf = sprintf("[%s]:[%s]", $this->cPanelUser, $this->cPanelPass); 

    //Build the path. If it begins with/we go and paste at root 
    if ($cPanelPage[0] == '/') { 
     $url = $this->cPanelRoot.substr($cPanelPage, 1); 
    } 
    else { 
     //Build the path - if begins with/we go and paste relative 
     $url = $this->cPanelRel.$cPanelPage; 
    } 

    curl_setopt ($curl, CURLOPT_URL, $url."?".$sPostVars); 
    curl_setopt ($curl, CURLOPT_TIMEOUT, 30); 
    curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5))); 
    curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt ($curl, CURLOPT_FAILONERROR, 0); 
    curl_setopt ($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
    curl_setopt ($curl, CURLOPT_USERPWD, $loginf); 
    $html = curl_exec ($curl); 
    echo 'Errors: ' . curl_errno($curl) . ' ' . curl_error($curl) . '<br><br>'; 
    echo $html; 
    curl_close ($curl); 

    //print_r($url); 
    return $html; 
    } 

} 

我在一台服务器上使用这个脚本,并试图在另一台服务器上登录并运行一个fastastico脚本。这是错误输出:错误:7无法连接到主机

我已经多次检查用户名和密码。

回答

0

你得到的错误似乎更多的是一个连接问题,而不是一个PHP /卷曲相关的问题。

  • 本机能够访问互联网吗?
  • 其DNS服务器配置是否正确?
  • 你可以ping的cPanel主机?
  • 是否有一个新的防火墙,阻止你在cPanel主机?
+0

我可以通过浏览器登录到cPanel。它的共享主机,所以我不能回答DNS和防火墙的问题。我使用hostgator托管宝贝计划。 – Chris