I have a PHP page (test.php) that has to respond to a HTTP GET request sent from an android application. The response has to be via a json object. How do I do that?
For reference :- Below is a php code that checks the login details from a login form. The http request would be the username and password sent from an android application that contains the login form. The response from this page would be the success or failure message.
<?php
session_start();
require('connect.php');
if (isset($_GET['username']) and isset($_GET['password']))
{
$username = $_GET['username'];
$password = $_GET['password'];
$query = "SELECT * FROM `staff_reg` WHERE username='$username' and password='$password'";
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1)
{
$_SESSION['username'] = $username;
}
else
{
echo "Invalid Username or Password";
}
}
if (!isset($_SESSION['username']))
{
echo "Session Expired";
echo "<br><a href='staff_login.php'>Click here</a> to login again";
echo "<br><a href='index.html'>Click here</a> to go back to the homepage";
$username = $_SESSION['username'];
}
else{
$username = $_SESSION['username'];
echo "<p>Welcome ".$username."<br>";
echo "This is the Staff Portal<br>";
echo "<a href='logout.php'>Logout</a></p>";
?>