Php + curl issue Resource id # 2 on curl_init

curlPHP

php + curl issue Resource id # 2 on curl_init:

 $url = "https://example.com:4433/deviceservice/authorize?login=query"; // URL JSON
        $ch = curl_init($url);
        echo $ch; //write Resource id # 2
        if( $ch )
        {
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE);
            $json = curl_exec( $ch );
            $json = json_decode($json);
        } else {
            echo 'nothing';
            }

What am I doing wrong?

Best Answer

If you are not on a host with SSL so you should bypass the SSL verification

<?php
    $url = "https://example.com:4433/deviceservice/authorize?login=query"; 
    $ch = curl_init($url);
    echo $ch; //write Resource id # 2
    if( $ch )
    {
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        $json = curl_exec( $ch );
        $json = json_decode($json);
    } else {
        echo 'nothing';
    }