I’m writing a relatively simple if statement to process the response of a web-service
The below code will output the type of data that’s being returned and the value of it:
$response = $client->__getLastResponse();
echo $response;
echo gettype($response);
For a correct response, I get ‘true string’
For an incorrect response, I get ‘false string’
So I need an if statement to process whether it’s true or false:
if($response == "true"){
echo "Logged In";
} else {
echo "Not Logged In";
}
Whatever response I get, I always receive “Not Logged In”
I’ve tried the === operator also, but to no avail.
Can someone help?
Provided that’s you actual code, you have
echo $response . gettype( $response )which yields “true string”, right? If so, there’s a space after “true”. Try to trim the response:Apart from that, debugging is really easy using
var_dump, as that will display quotes around the value and the total length of the string, making the additional space pop-up much easier to spot.