简体   繁体   English

php curl结果无效

[英]php curl result is invalid

This is my first time posting here! 这是我第一次在这里发布! :) I have made a php license generation and validation system. :)我已经制作了一个PHP许可证生成和验证系统。 The server end communicates with the mysql database and outputs a json result like the following: 服务器端与mysql数据库通信并输出json结果,如下所示:

{"valid":"true","info":{"id":"1","expire":"1421811123"}} {“有效”:“真”,“信息”:{“ id”:“ 1”,“到期”:“ 1421811123”}}

The problem is on the client server where i have the following script: 问题出在我具有以下脚本的客户端服务器上:

<?php


$key_info['key'] = "KEY"];
$serverurl = "http://URLTOSERVER";

$ch = curl_init ($serverurl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt ($ch, CURLOPT_POST, true);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $key_info);

$result = curl_exec ($ch);
$result = json_decode($result, true);

if($result['valid'] == true){

        echo "valid";
}
else {
        die("Invalid Key!");

}


?>

When i run this i get "valid" every time, even when i enter the wrong key - i have tried printing the output and i can confirm that. 当我运行此命令时,即使我输入了错误的密钥,我也会每次都“有效”-我已经尝试打印输出,并且我可以确认这一点。

Please advise. 请指教。

Thanks. 谢谢。

Your JSON contains a string true, not a boolean true. 您的JSON包含字符串true,而不是布尔值true。 Any string in there will pass == true . 那里的任何字符串都将通过== true

if($result['valid'] == 'true'){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM