A few years ago I created a backend (PHP to get some json data) for some mobile apps of mine. I haven't touched this code since then. Now it stopped working weeks ago. I'm not a backend developer so I don't have much experience here, but a few years ago I thought it would be better to create my own backend instead of using Firebase/Serverless... which wasn't my best idea: )
What I tried:
<!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.addEventLis tener;}catch(e){return !!0;} }, y=function(y,z){x() ? document.addEventLis tener("DOMContentLoaded",y,z) : document.attachEvent("onreadystatechange",y);}; y(function(){ document.getElementById('wsidchk').value = west + east; document.getElementById('wsidchk-form').submit(); }, false); })(); </script> </body> </html>
This is my php file:
$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);
Can someone explain to me what I'm doing wrong/what can be changed?
Looks
if($_SERVER['REQUEST_METHOD'] == 'GET')
There is no$response
. Unless there is more in the code,$response
is undefined.Something like this should do the trick! I also recommend looking at the HTTP response, such as HTTP 405. https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
Edit: I saw your update and I'm sorry, but it raises more questions. In other words, what does
$db->getHighestRatingWith31Results();
do? FunctionsaveResultOfQueryToArray()
accepts one parameter, but the usage is to provide two parameters to the function? saveResultOfQueryToArray is calling mysqli_fetch_array(), which requires a mysqli_result instance.This is my suggestion:
saveResultOfQueryToArray()
or consider passing it by reference. https://www.php.net/manual/en/language. references.pass.php