2010-06-08 26 views
12

我從Gmail導入聯繫人到我的網頁.....curl_init undefined?

的過程中不工作,由於這個錯誤

'curl_init'沒有定義

我得到的建議是到

  1. 取消註釋目的地curl.dll
  2. 複製以下庫到windows/SYSTEM32目錄:ssleay32.dlllibeay32.dll
  3. 副本php_curl.dll到Windows/SYSTEM32

嘗試所有這些後,我刷新我的XAMPP,但即使是這樣發生的錯誤。

這是我的頁面,在這裏我想導入Gmail聯繫人:

<?php 
resource curl_init ([ string $url = NULL ]) 

$ch = curl_init(); 


curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); 
curl_setopt($ch, CURLOPT_HEADER, 0); 


curl_exec($ch); 


curl_close($ch); 
?> 

<?php 
echo "hi"; 

if($_POST['submit'] != '') { 
    echo "hi"; 

    $clientlogin_url = "https://www.google.com/accounts/ClientLogin"; 


    $clientlogin_post = array(
    "accountType" => "HOSTED_OR_GOOGLE", 
    "Email" => $_POST['Email'], 
    echo "Passwd" => $_POST['Passwd'], 
    "service" => "cp", 
    "source" => "tutsmore/1.2" 
    ); 


    $curl = curl_init($clientlogin_url); 


    curl_setopt($curl, CURLOPT_POST, true); 


    curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post); 


    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 


    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 


    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 


    $response = curl_exec($curl); 



    preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches); 
    $auth = $matches[1]; 


    $headers = array("Authorization: GoogleLogin auth=" . $auth); 


    $curl = curl_init('http://www.google.com/m8/feeds/contacts/default/full?max-results=10000'); 


    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 


    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 


    $feed = curl_exec($curl); 


    echo "contacts".$contacts=array(); 


    $doc=new DOMDocument(); 



    if (!empty($feed)) $doc->loadHTML($feed); 


    $xpath=new DOMXPath($doc); 


    $query="//entry"; 
    $data=$xpath->query($query); 

    foreach ($data as $node) { 


     $entry_nodes=$node->childNodes; 


     $tempArray=array(); 


     foreach($entry_nodes as $child) { 


      $domNodesName=$child->nodeName; 

      switch($domNodesName) { 
       case 'title' : { 
         $tempArray['fullName']=$child->nodeValue; 
        } break 
        ; 
       case 'email' : { 
         if (strpos($child->getAttribute('rel'),'home')!==false) 
          $tempArray['email_1']=$child->getAttribute('address'); 
         elseif(strpos($child->getAttribute('rel'),'work')!=false) 
          $tempArray['email_2']=$child->getAttribute('address'); 
         elseif(strpos($child->getAttribute('rel'),'other')!==false) 
          $tempArray['email_3']=$child->getAttribute('address'); 
        } break 
        ; 
      } 
     } 
     if (!empty($tempArray['email_1']))$contacts[$tempArray['email_1']]=$tempArray; 
     if(!empty($tempArray['email_2'])) $contacts[$tempArray['email_2']]=$tempArray; 
     if(!empty($tempArray['email_3'])) $contacts[$tempArray['email_3']]=$tempArray; 
    } 
    foreach($contacts as $key=>$val) { 

     echo $key."<br/>"; 
    } 
} 
else { 

    ?> 
<form action="<?=$PHP_SELF?>" method="POST"> 
    <table> 
     <tr> 
      <td>Email:</td><td><input type="text" name="Email" /></td> 
     </tr> 
     <tr> 
      <td>Password:</td><td><input type="password" name="Passwd" /></td> 
     </tr> 
     <tr><td colspan="2" align="center">tutsmore don't save your email and password trust us.</td></tr> 
     <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Get Contacts" /></td></tr> 
    </table> 
</form> 
    <?php 
} 
?> 

此代碼是完全提供調試;如果需要優化,我會嘗試優化代碼。

回答

8

創建一個新的PHP文件 - 像temp.php - 而只需添加:

phpinfo(); 

它應該給你整個PHP配置的信息。滾動瀏覽已安裝的庫並查看cURL是否存在。如果沒有,請點擊手冊 - http://php.net/manual/en/book.curl.php - 並進行設置。這裏的說明很不錯。

2

resource curl_init ([ string $url = NULL ])

這是否真的出現在你的源代碼?如果是這樣,註釋掉它,因爲它只是curl_init返回類型和參數的文檔。

現在,如果curl在這一點上仍然給你帶來麻煩,你需要檢查php.ini並確保extension=php_curl.dll在它前面沒有;。 (我不能說這是你的第一個評論意味着什麼。)然後使用XAMPP重新啓動Apache。

30

安裝捲曲,使用PHP,你安裝PHP

+6

看來他使用Windows,而不是Linux。 – 2012-09-12 19:07:49

+0

來完成這個我不得不''php5enmod curl'和'debian服務apache2 restart' – steven 2015-08-20 10:15:38

0

我用這個代碼塊學習,如果一個客戶端的主機/服務器有捲曲或不安裝

後,您只需鍵入命令

sudo apt-get install php5-curl 

[email protected]_version(); 
$cv=$ci["version_number"]; 
if($cv) echo "curl installed"; 
else echo "curl is not installed"; 
1

對於XAMMP服務器,去你的php.ini 文件從的是開始去除;馬克低線 -

;extension=php_curl.dll 


重啓Apache服務器,現在它會正常工作:) ..

2

與Linux: sudo apt-get install php5.6-curl(PHP5捲曲消失) 然後重新啓動Apache(sudo service apache2 restart

也對PHP命令行,爲作曲家,這樣,簡單地增加sudo apt-get install php-curl將工作,因爲我覺得'其演技在其活動版本

相關問題