real_escape_string($token); // Prepare and bind $stmt = $mysqli->prepare("SELECT * FROM users WHERE token = ?"); $stmt->bind_param("s", $token); // Execute statement $stmt->execute(); // Get result $result = $stmt->get_result(); $response = array(); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $response['success'] = "true"; $response['message'] = "Success"; $response['username'] = $row['username']; $response['email'] = $row['email']; } else { $response['success'] = "false"; $response['message'] = 'Invalid token.'; $response['username'] = ""; $response['email'] = ""; } // Close connections $stmt->close(); $mysqli->close(); // Return JSON response header('Content-Type: application/json'); echo '{"success":' . $response['success'] . ', "message":"' . $response['message'] . '", "username":"' . $response['username'] . '", "email":"' . $response['email'] . '"}';