Question

Possible Duplicate:
return a specific http status code with php

How can I programmatically send specific http statuscodes with php? Is there any Method or even a class for this?

Was it helpful?

Solution

The header() function is what you need.

void header ( string $string [, bool $replace = true [, int $http_response_code ]] )

Place it right after the first <?php tag for the script rendering the response output.

You should refer http://php.net/manual/en/function.header.php

OTHER TIPS

Look at the header() function:

header('HTTP/1.0 404 Not Found');

Put that before any output of your script.

Send a header() before you send anything else to the client. Some possible status headers follow:

header('HTTP/1.1 200 OK');

// Page was not found:
header('HTTP/1.1 404 Not Found');

// Access forbidden:
header('HTTP/1.1 403 Forbidden');

// The page moved permanently should be used for
// all redrictions, because search engines know
// what's going on and can easily update their urls.
header('HTTP/1.1 301 Moved Permanently');

// Server error
header('HTTP/1.1 500 Internal Server Error');

// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top