skip to Main Content
$curl      = curl_init();
curl_setopt_array($curl   , [

CURLOPT_RETURNTRANSFER =>TRUE,

CURLOPT_URL => 'https://ortam.etu.edu.tr/Services/get_user_card_information/?apikey=XXXXXXXXX&username=ZZZZZZZZZZ',

 ]);
$response = curl_exec($curl);
$response = json_decode($response, TRUE);

var_dump($response);

I was able to get a response from a different API call, but I cannot get a response from this API, it comes back as NULL.

https://api.nasa.gov/neo/rest/v1/feed?start_date=2023-12-01&end_date=2023-12-08&api_key=XXXXXXXXXXXXXXX
This API works correctly.

2

Answers


  1. If you making a request to API endpoint which has SSL Certificate you should set CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER options to false

    Credit: https://stackoverflow.com/a/15237205/12571947

    According to documentation: to verify host or peer certificate you
    need to specify alternate certificates with the CURLOPT_CAINFO option
    or a certificate directory can be specified with the CURLOPT_CAPATH
    option.

    Not Recommend (Only for Development)

    
    $curl = curl_init();
    
    curl_setopt_array($curl, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYHOST => false, // Skip SSL Verification
        CURLOPT_SSL_VERIFYPEER => false, // add this line
        CURLOPT_URL => "https://ortam.etu.edu.tr/Services/get_user_card_information/?apikey=XXXXXXXXX&username=ZZZZZZZZZZ"
    ]);
    
    $response = curl_exec($curl);
    
    

    Recommend

    Answer Credit to: https://stackoverflow.com/a/18972719/12571947

    The problem is solved by this certificate which is provided by the cURL creator (extracted from Mozilla): https://curl.haxx.se/ca/cacert.pem

    So after downloading this cacert.pem file into your project, in PHP you can now do this:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
    curl_setopt($ch, CURLOPT_CAINFO, "/path/to/cacert.pem");
    

    Alternatively, this can be set globally by adding the following to your php.ini

    curl.cainfo=/path/to/cacert.pem
    
    Login or Signup to reply.
  2. You need to check for any errors in the cURL request using curl_error function which returns any error happens in the request phase:

    $error = curl_error($curl);
    var_dump($error); // Output: string(63) "SSL certificate problem: unable to get local issuer certificate"
    

    That’s means that there is an issue with the SSL certificate on the requested endpoint.

    To solve this, you need to disable the SSL verification using

    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    

    or to request the UN-SECURED http like:

    CURLOPT_URL => 'http://ortam.etu.edu.tr/Services/get_user_card_information/?apikey=ZZZZZ&username=XXXX',
    

    Note the http://ortam. instead of https://ortam.

    However, this is not a good idea at all to disable the SSL verification.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search