php curl_init 未定义?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2997040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:22:25  来源:igfitidea点击:

curl_init undefined?

phpcurl

提问by udaya

I am importing the contacts from gmail to my page .....

我正在将联系人从 gmail 导入我的页面.....

The process does not work due to this error

由于此错误,该过程不起作用

'curl_init'is not defined

'curl_init'没有定义

The suggestion i got is to

我得到的建议是

  1. uncomment destination curl.dll
  2. copy the following libraries to the windows/system32 dir: ssleay32.dlland libeay32.dll
  3. copy php_curl.dll to windows/system32
  1. 取消注释目标 curl.dll
  2. 将以下库复制到 windows/system32 目录:ssleay32.dlllibeay32.dll
  3. 将 php_curl.dll 复制到 windows/system32

After trying all these, I refreshed my xampp, but even then error occurs.

在尝试了所有这些之后,我刷新了我的 xampp,但即使这样也会发生错误。

This is my page where I am trying to import the gmail contacts:

这是我尝试导入 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
}
?>

This code is completely provided for debugging; if any optimization is needed, I will try to optimize the code.

这段代码完全是为了调试提供的;如果需要任何优化,我会尝试优化代码。

采纳答案by CaseySoftware

Create a new php file - like temp.php - and just add:

创建一个新的 php 文件——比如 temp.php——然后添加:

phpinfo();

It should give you information of your entire PHP configuration. Scroll through the installed libraries and see if cURL is there. If not, hit the Manual - http://php.net/manual/en/book.curl.php- and get it setup. The instructions there are pretty good.

它应该为您提供整个 PHP 配置的信息。滚动浏览已安装的库并查看 cURL 是否存在。如果没有,请点击手册 - http://php.net/manual/en/book.curl.php- 并进行设置。那里的说明非常好。

回答by edwin

to install curl with php, you just type the command

用php安装curl,你只需输入命令

sudo apt-get install php5-curl

after your install php

安装 php 后

回答by PolarTheDog

with linux: sudo apt-get install php5.6-curl(php5-curl is gone) then restart apache (sudo service apache2 restart)

使用 linux: sudo apt-get install php5.6-curl(php5-curl 不见了) 然后重启 apache ( sudo service apache2 restart)

also for command line php, for composer and such, simply adding sudo apt-get install php-curlwill work because I 'think' its acting on its active version

也适用于命令行 php、作曲家等,只需添加即可,sudo apt-get install php-curl因为我“认为”其作用于其活动版本

回答by Powerlord

resource curl_init ([ string $url = NULL ] )

resource curl_init ([ string $url = NULL ] )

Does this really appear in your source code? If so, comment it out, as it's just documentation of curl_init's return type and arguments.

这真的出现在您的源代码中吗?如果是这样,请将其注释掉,因为它只是 curl_init 返回类型和参数的文档。

Now, if curl is still giving you trouble at this point, you need to check in php.iniand make sure extension=php_curl.dlldoes not have a ;in front of it. (I can't tell if that's what you meant by your first comment or not.) Then use XAMPP to restart Apache.

现在,如果此时 curl 仍然给您带来麻烦,您需要检查php.ini并确保extension=php_curl.dll;前面没有 。(我不知道这是否是您的第一条评论的意思。)然后使用 XAMPP 重新启动 Apache。

回答by Rohit Suthar

For xammp server, go to your php.inifile and remove the ;mark from the beginning of the below line -

对于 xammp 服务器,转到您的php.ini文件并删除;以下行开头的标记 -

;extension=php_curl.dll


restart your apache server, now its will work fine :)..


重新启动您的 apache 服务器,现在它可以正常工作了:)..

回答by Erdin? ?orbac?

I use this code block to learn if a client's host/server has curl installed or not

我使用此代码块来了解客户端的主机/服务器是否安装了 curl

$ci=@curl_version();
$cv=$ci["version_number"];
if($cv) echo "curl installed";
else echo "curl is not installed";