PHP return type not as same as i expect

53 views Asked by At

I'm using curl for sending data and then in response i'm giving some values. If it satisfies then the response should be true and if not then it will return string error message.

My code is as below,

if(curl_exec($ch) === true){
        return true;
}else{
        return curl_exec($ch);
}

In my response file i wrote this,

if($_POST['license']=='123456'){
        echo 'License already in use';
}else{
        echo true;
}

I think echo true is same and first condition curl_exec($ch)===true) should satisfy. I cannot understand where i am going wrong. Please drive me in right way.

Edit

I dump it using var_dump and its showing string type insead boolean -> string '' (length=0)

My curl code is

    $site = array('license' => $this->key, 'domain' => $this->domain, 'server' => $_SERVER['HTTP_HOST']);


    curl_setopt($ch, CURLOPT_URL, EXTENSION_VERIFY_URL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $site);

    if(curl_exec($ch) === true){
        return true;
    }else{
        return curl_exec($ch);
    }
1

There are 1 answers

2
Daan Wilmer On

Calling curl_exec() twice is probably what fails. Instead you should store the return value in a variable (e.g. $result = curl_exec()), and use that to test.

Besides that, try echoing something like t instead of true and f:License already in use instead of the string. That way you always have a string returned, if everything works correctly.