0

In reference to this previous question: Connect through HTTPS instead of HTTP

Would this be the good way to make a secure API call with HTTPS?

public function demo(){
    $Username = 'username';
    $Password = 'xxxxxxxxx';
    $url = 'http://api.text-connect.co.uk/api/api.php?Username='.$Username.'&Password='.$Password.'&Action=checkcredits';


    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);


    $result = curl_exec($ch);
    curl_close($ch);

    echo $result;
}

Should i use https instead of http at the $url variable?

Community
  • 1
  • 1
Alvaro
  • 40,778
  • 30
  • 164
  • 336

1 Answers1

0

Unless you use an https://... URL, no HTTPS secured connection will be established.

The _SSL_ options you are setting only specify the behavior in case an HTTPS connection is made. They don't turn an HTTP URL into an HTTPS URL.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • When use `https` on my `$url` variable it doesn't work anymore. Why is that? Am I doing anything wrong? – Alvaro Nov 30 '12 at 11:07
  • "Doesn't work" is not a detailed enough problem description to be able to help. – deceze Nov 30 '12 at 11:08
  • It keeps loading and finally it shows this message `Error: Maximum execution time of 30 seconds exceeded`. Doesn't look good... with `http` it works fast. What any other information you need to be able to help me? – Alvaro Nov 30 '12 at 11:14
  • After changing the execution limit time it shows `$result` with a `false` value. – Alvaro Nov 30 '12 at 11:15
  • Open a new question with as many information as you can provide. The comments to an accepted answer are not the place to debug this. – deceze Nov 30 '12 at 11:15
  • I have opened another one: http://stackoverflow.com/questions/13644280/failing-to-connect-through-https-and-curl-at-php – Alvaro Nov 30 '12 at 11:24