我有一個PHP page(test.php),它必須響應從android應用程序發送的HTTP GET請求。 響應必須通過json對象。我怎麼做?在php中響應http獲取請求與json對象
作爲參考: - 下面是一個PHP代碼從一個登錄表單檢查登錄詳細信息。 http請求將是包含登錄表單的android應用程序發送的用戶名和密碼。此頁面的響應將是成功或失敗消息。
<?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>";
?>
所有的答案都是有用的,但這種感覺更「有用」。謝謝你們 – 2015-04-15 08:57:03