PHP, CURL. What does curl_exec return?

后端 未结 1 1677
我寻月下人不归
我寻月下人不归 2020-12-06 05:05

I\'m trying to set an API with a payment processor. Below is the code they provided me. There are some information in the $result variable that I want, what I don\'t underst

1条回答
  •  执笔经年
    2020-12-06 05:21

    From the manual:

    Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.

    Your code already contains this line (which is good):

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    

    The 1 means you will receive an explanatory result back from $result = curl_exec ($ch) instead of just true or false.

    Your error checking code could therefore look like:

    $result = curl_exec ($ch);
    if($result === FALSE) {
        die(curl_error($ch));
    }
    

    You can also check they type of variable returned via var_dump: var_dump($result).

    0 讨论(0)
提交回复
热议问题