在本地主机上它运行完美但在线给出警告 Curl_setopt() expects parameter 1 to be resource, null given in

On localhost it runs perfectly but online gives the warning Curl_setopt() expects parameter 1 to be resource, null given in

在我的本地主机上,它运行完美,但在我的虚拟主机上,出现以下错误。

PHP Warning: curl_setopt() expects parameter 1 to be resource, null given in \WINDOWSxxxx.LOCAWEB.COM.BR\xxxx\xxxxx\pagamento.php on line 15, 16, 18 and 19

不知道是不是语法错误?

<?php

    include 'config.php';
    //session_start();
    #create the request
    $url = URL_PAGSEGURO."sessions?email=".EMAIL_PAGSEGURO."&token=".TOKEN_PAGSEGURO;

    //http://br2.php.net/manual/pt_BR/function.curl-setopt.php

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded; charset=UTF-8"));
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, true);

    $retorno = curl_exec($curl);
    curl_close($curl);

    $xml = simplexml_load_string($retorno);
    echo json_encode($xml);

我是在 PHP 上使用 curl 的新手(请不要做出苛刻的判断),发现它对用户更友好,输入更少。希望它能有所帮助。我没有包括你所有的参数,这只是为了向你展示另一种方式。

$curl = curl_init();

$apiURL; // This will have to be set
$data; // This will have to be set

curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_POSTFIELDS => $data,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POST=>true,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_RETURNTRANSFER => true;
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
        'x-api-key: nPwrkTQyjW7DnFdvU='
    )
));

$response = json_decode(curl_exec($curl), true);
curl_close($curl);