几年前,我为我的一些移动的应用程序创建了一个后端(PHP以JSON格式获取一些数据)。从那以后我就没有碰过这个代码。现在它在几周前停止工作了。我不是一个后端开发人员,所以我在这里没有太多经验,但几年前我认为创建自己的后端会更好,而不是使用Firebase/Serverless.不是我最好的主意:)
我尝试了什么:
- 用Chrome检查URL-->一切正常(我可以看到我的JSON数据)
- 在应用程序内部或Postman中检查:(Header:Content-Type text/html)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>One moment, please...</title>
<style>
body {
background: #F6F7F8;
color: #303131;
font-family: sans-serif;
margin-top: 45vh;
text-align: center;
}
</style>
</head>
<body>
<h1>Please wait while your request is being verified...</h1>
<form id="wsidchk-form" style="display:none;" action="/z0f76a1d14fd21a8fb5fd0d03e0fdc3d3cedae52f" method="get">
<input type="hidden" id="wsidchk" name="wsidchk"/>
</form>
<script>
(function(){
var west=+((+!+[])+(+!+[]+!![]+!![]+!![]+[])+(+!+[]+!![]+!![]+!![])+(+!+[]+!![]+!![]+!![]+[])+(+!+[])+(+!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+[])+(+!+[]+!![]+!![]+!![]+!![])+(+!+[]+[])),
east=+((+!+[])+(+!+[]+!![]+[])+(+!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![])+(+!+[]+[])+(+![])+(+!+[]+!![]+[])+(+!+[]+!![])+(+!+[]+!![]+!![]+[])),
x=function(){try{return !!window.addEventListener;}catch(e){return !!0;} },
y=function(y,z){x() ? document.addEventListener("DOMContentLoaded",y,z) : document.attachEvent("onreadystatechange",y);};
y(function(){
document.getElementById('wsidchk').value = west + east;
document.getElementById('wsidchk-form').submit();
}, false);
})();
</script>
</body>
</html>
字符串
这是我的PHP文件:
$response = array();
function saveResultOfQueryToArray($result){
global $response;
$response['workouts'] = array();
while($row = mysqli_fetch_array($result)){
$temp = array();
// $temp['aufruf'] = $aufruf;
$temp['error'] = false;
$temp['workoutname'] = $row['workoutname'];
$temp['duration'] = $row['duration'];
...
array_push($response['workouts'],$temp);
}
}
if($_SERVER['REQUEST_METHOD']=='GET') {
$db = new DbOperation();
$users = $db->getHighestRatingWith31Results();
saveResultOfQueryToArray($users, $chooseMethod);
}
else {
$response['error'] = true;
$response['message'] = "Invalid Request";
}
echo json_encode($response);
型
有人能告诉我我做错了什么吗?有什么可以改变的吗?
1条答案
按热度按时间lskq00tm1#
看起来
if($_SERVER['REQUEST_METHOD'] == 'GET')
没有$response
。除非有更多的代码,否则$response
是未定义的。字符串
我还建议查看HTTP响应,比如HTTP 405. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
编辑:所以我看到你的更新,我很抱歉,但它引发了更多的问题。也就是说,
$db->getHighestRatingWith31Results();
做什么?函数saveResultOfQueryToArray()
接受一个参数,但用法是给函数两个参数?saveResultOfQueryToArray调用mysqli_fetch_array(),它需要一个mysqli_result示例。以下是我的建议:
saveResultOfQueryToArray()
返回$response,要么通过引用传递。https://www.php.net/manual/en/language.references.pass.php