Reputation: 31
Im trying to get this to work, im new to slim framework
$app->get('/GetIpInfo/{format}/{ip}/{api_key}', function($request, $response, $args){
global $dbc;
$ip = $args['ip'];
$private_key = $args['api_key'];
$format = $args['format'];
if($format != "xml" or $format!= "json")
{
echo "unknown format parameter sent";
die();
}
It doesnt matter if I do xml or json it always outputs unknown format parameter sent
Upvotes: 0
Views: 33
Reputation: 430
Your problem is only about properly understanding logical operators. Look:
if($format != "xml" or $format!= "json")
According to this statement, if $format
is equals to "xml", the first comparison is false and it then evaluates the second, which is true. So it enters and returns "unknown format"
if $format is equals to "json", the first comparison is true straight away, and it enters the "if" and returns "unknown format" as well, without considering the second part.
I believe you wanted something like:
if($format != "xml" and $format!= "json")
this way it will only return "unknown format" if it is not xml nor json. If you use OR it will enter as soon as any is evaluated to true. If you use AND it will reject as soon as any one is false.
EDIT
I think is worth mentioning that you have a tautology on your code i.e. it will always be evaluated to true and returns "unknown format" regardless of the input. The reason was shown above.
Upvotes: 1