1

I use curl with the Riot API. Everything is working fine on my live server but isn't in local. The curl extension is enabled in WampServer and I don't get any error messages, it's just a blank page.

Here's my code even if it's not actually relevant.

<?php 
    $private_key = "XXX";
    function summoner_name($summoner, $server, $private_key) {
        $summoner_encoded = rawurlencode($summoner);
        $summoner_lower = strtolower($summoner_encoded);
        $curl_url = 'https://' . $server . '.api.pvp.net/api/lol/' . $server . '/v1.4/summoner/by-name/' . $summoner . '?api_key='.$private_key;
        $curl = curl_init($curl_url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
        curl_close($curl);
        return $result;
    }

    function summoner_info_array_name($summoner) {
        $summoner_lower = mb_strtolower($summoner, 'UTF-8');
        $summoner_nospaces = str_replace(' ', '', $summoner_lower);
        return $summoner_nospaces;
    }

    $summoner = "Test";
    $server = "euw";
    $summoner_info = summoner_name($summoner, $server, $private_key);
    $summoner_info_array = json_decode($summoner_info, true);
    $summoner_info_array_name = summoner_info_array_name($summoner);
    $summoner_id = $summoner_info_array[$summoner_info_array_name]['id'];
    $summoner_name_display = $summoner_info_array[$summoner_info_array_name]['name'];
    $summoner_icon = $summoner_info_array[$summoner_info_array_name]['profileIconId'];
    echo '<img src="http://ddragon.leagueoflegends.com/cdn/6.9.1/img/profileicon/'.$summoner_icon.'.png" /><br/><hr>'.$summoner_name_display;
?>   

And here's my phpinfo() for curl extension.
Thanks in advance! enter image description here.

Will
  • 24,082
  • 14
  • 97
  • 108
Quinox
  • 573
  • 3
  • 14
  • What does `var_dump($result);` on the line before `return $result;` look like? – Will May 21 '16 at 22:39
  • "I:\www\riot_api_test\test_local.php:24:boolean false" :/ – Quinox May 21 '16 at 22:41
  • Thanks, okay, now replace that `var_dump(...);` with `var_dump(curl_error($curl));` – Will May 21 '16 at 22:43
  • Okay, it makes sense. Here's the error code: "I:\www\riot_api_test\test_local.php:23:string 'SSL certificate problem: unable to get local issuer certificate' (length=63)" – Quinox May 21 '16 at 22:45

2 Answers2

2

You can always call curl_getinfo() and curl_error() functions to check the problems on latest curl query.

Like this:

$result = curl_exec($curl);
if ($result === false) {
    echo "Something is wrong here!\n".var_export(curl_error($curl), true)
         . "\nQuery:".var_export(curl_getinfo($curl), true); exit();
}
Will
  • 24,082
  • 14
  • 97
  • 108
Maksim Volkov
  • 1,566
  • 1
  • 10
  • 4
2

So, first, as @MaksimVolkob pointed out, and as we discussed in the comments, the first step to resolving these errors is to see what the error message actually is. curl_error() will give you this information.

Specifically, you're getting an SSL/TLS error:

SSL certificate problem: unable to get local issuer certificate' (length=63)

If you don't care about security (I do not recommend this for production applications, ever.), you can disable the SSL verification step that is failing:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

The better way is to fix your CA certificate information by setting CURLOPT_CAINFO. This blog post explains this pretty well.

Edit: As OP discovered, this question has more specifics about getting cURL to recognize the proper CA certificate.

Community
  • 1
  • 1
Will
  • 24,082
  • 14
  • 97
  • 108
  • Thank you for the link and even if I only get the issue on local server, I'd like to resolve it the proper way. Atm, I get the following error message for "curl_setopt($curl, CURLOPT_CAINFO, getcwd() . "/riot_api.cer");" "I:\www\riot_api_test\test_local.php:32:string 'error setting certificate verify locations: CAfile: I:\www\riot_api_test/riot_api.cer CApath: none' (length=102)". I verified if my certificate is actually at this spot and it's fine. Should I define the path with the CApath ? I'll try anyway ! – Quinox May 21 '16 at 23:20
  • 1
    I finally resolved it and followed the steps as described in this post: [cURL error 60: SSL certificate: unable to get local issuer certificate](http://stackoverflow.com/questions/29822686/curl-error-60-ssl-certificate-unable-to-get-local-issuer-certificate?rq=1). Thanks for the help ! – Quinox May 22 '16 at 00:01
  • Awesome, no problem, glad to help! – Will May 22 '16 at 01:53