【发布时间】:2019-01-21 07:16:58
【问题描述】:
当我通过 URL 传递一个值并输入一个有效值时,我使用内部服务器时遇到问题,显示他没有滚动查看我的代码的消息:
// 从此 URL 传递值:
http://localhost/test/get.php?name=aa
<?php
// include Marei DB Class
include 'DB.php';
// get content input and create json object to parse it
$data = file_get_contents("php://input");
$obj = json_decode($data);
// create db instance to use marei db queris
$db = DB::getInstance();
// set type of header response to application/json for respone
header('Content-Type: application/json');
if(!empty($_GET["name"])){
print "{\"status\":0,\"message\":\"Username is Non !\"}" ;
}else{
print "{\"status\":0,\"message\":\"Username is Don !\"}" ;
}
?>
// print these lines :
{"status":0,"message":"Username is Non !"}
【问题讨论】:
-
我没有看到问题。
$_GET["name"]是aa,不为空。所以它会打印第一条消息。 -
你确定你的输出信息是正确的吗?您的 if 读取“如果不为空”,这意味着它执行顶部代码块(如果存在)
-
不要用字符串生成 JSON,你应该总是使用
json_encode()。 -
您的代码在读取时正在执行.. 它说用户名不是因为那是您编码的。 $_GET['name'] 不为空。
-
是的,我确定,它打印了这些行:{"status":0,"message":"Username is Non !"}