2010-06-08 56 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将工作,因为我觉得'其演技在其活动版本