Return html status page as part of a PHP query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidhopkins
Forum Commoner
Posts: 41
Joined: Thu Jun 10, 2010 7:52 am

Return html status page as part of a PHP query

Post by davidhopkins »

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

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);
  }
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
Post Reply