OKHTTP - 发布用户输入数据,检索JSON响应以确定成功

I've been thinking in how to do this. I've read trough the OKHTTP documentation, I have an idea on how to handle this but I'm not entirely sure.

I'll have the user submit three fields ( Username, Password, Database ). I'll have a PHP file uploaded to my host which accepts post data. ( It's pure PHP, so no html. It just accepts data posted to the page. )

Once the values have been submitted, i'll perform a check. Credentials found? Return/echo JSON array ( Success/ Failure ). I could check if the array key " success " equals either 1 || 0. If 1, show a toast that user has been logged in successfully.

Now, as for the question. Is my logic correct? If not, how would you do it? Do you have any tips for me? Any examples?

To send the "authorization" in HTTP requests you have to set the header to 403.

header('HTTP/1.0 403 Forbidden');

echo 'You are forbidden!';

But when I send JSON via a PHP page, I am using a 'generator' to make it easy, like Simple JSON for PHP.

include('includes/json.php');

$json = new json();

$json->add('status', '403');
$json->add('message', 'YOU ARE FORBIDDEN!');

$json->send();

UPDATE : Headers if you want to send "home made" JSON :

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

EDIT :

There is also the Slim Framework, I didn't try it, but it seems very efficient! Simple JSON for PHP is as the name says, just to create a JSON & send it, it do not use make use of routes at all.