$app->get('/checkAccount', function () use ($app) {
$app->response->setContentType('application/json', 'utf-8');
$username = null;
$password = null;
if (isset($_GET['Username'])) {
$username = $_GET['Username'];
}
if (isset($_GET['Password'])) {
$password = $_GET['Password'];
}
$user_id = User::verifyUser($username, $password);
if ($user_id == null) {
$status = 'Username and password have not authorized';
}
else {
$status = 'Username and password have authorized';
}
$data = array(
'Username' => urlencode($username),
'Password' => urlencode($password),
'Status' => urlencode($status),
);
echo urldecode(json_encode($data));
});
I have checked response header, why always text/html? I have set setContentType('application/json', 'utf-8')!!!!!!!!!!!!!
Here is response: HTTP/1.1 200 OK Date: Sat, 07 Jun 2014 00:48:33 GMT Server: Apache/2.4.4 (Win64) PHP/5.4.12 X-Powered-By: PHP/5.4.12 Content-Length: 102 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8
Page display is: {"Username":"sally","Password":"123456781","Status":"Username and password have authorized"}