Return html status page as part of a PHP query
Posted: Wed Aug 31, 2011 9:16 am
Good Afternoon all.
I am digging about trying to develop a simple API system. What i want to do is allow people to search for some candidate information stored in a database and have that returned in either XML or JSON format. I got all this working fine.
However i get into problems when i try to return html status page codes when an error occurs.
My code looks like
what im having trouble with is when checkresult ==0 i want a status code of 204 No Content but i cant seem to do it 
THanks in advanec
David
I am digging about trying to develop a simple API system. What i want to do is allow people to search for some candidate information stored in a database and have that returned in either XML or JSON format. I got all this working fine.
However i get into problems when i try to return html status page codes when an error occurs.
My code looks like
Code: Select all
if($checkResult == 0) {
$status = 200;
$message = 'You must be authorized to view this page.';
$signature ="test";// ($_SERVER['SERVER_SIGNATURE'] == '') ? $_SERVER['SERVER_SOFTWARE'] . ' Server at ' . $_SERVER['SERVER_NAME'] . ' Port ' . $_SERVER['SERVER_PORT'] : $_SERVER['SERVER_SIGNATURE'];
$body = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>hjgjgj </title>
</head>
<body>
<h1> ghjgjg</h1>
<p>' . $message . '</p>
<hr />
<address>' . $signature . '</address>
</body>
</html>';
echo $body;
}
}
else {
$query = "SELECT * FROM accUsers ORDER BY candidateID ASC LIMIT $number_of_posts";
$result = mysql_query($query,$link) or die('Errant query: '.$query);
}THanks in advanec
David