I have an API call for which I need to be able to run some checks and possibly return various status codes. I don't need custom views or anything else, I just need to return the correct code. If the user did not provide the correct credentials, I need to return the status of 401. If they did not send a supported request format, I need to return the status of 400.
Since this is an API, all I really want to do is set the status of the response and exit with a simple, stupid message about why the request failed (possibly using exit ). Enough to do this work, but I could not get it to work correctly. I tried using PHP header() and Cake $this->header() (all in the controller), but although I get an exit message, the header shows a status of 200 OK .
Using the following code, I get a message, but the header is not set. What am I missing?
if( !$this->auth_api() ) { header( '401 Not Authorized' ); exit( 'Not authorized' ); }
Rob Wilkerson May 28 '11 at 19:44 2011-05-28 19:44
source share