Status 200 always returned when setting status



First of all, great framework!

I’m struggling with this for a while. No matter what I do, it always returns status 200.

This is my code:

return $response->withJson($check, 500);

Also tried it like this:

$newResponse = $response->withStatus(400)->write(‘Bad Request’);
return $newResponse;

Status 200 is always returned. I’m running it locally (osx, wamp, apache), don’t know if that’s an issue.

Thanks in advance and keep up the great work.


Can you show us the controller/usecase who handle this request?


This is the code, stripped out the other methods…


include_once “…/…/DB.php”;

use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;

// Create App
$app = new \Slim\App;

// Make sure we can get the ip from the request
$app->add(new RKA\Middleware\IpAddress());

// Logging

$app->post(’/generate’, function (ServerRequestInterface $request, ResponseInterface $response, $args) {

$check = checkRequestCount('/generate', $request->getAttribute('ip_address'));
if($check) {
	return $response->withJson($check, 500);
} else {





The last else is empty :smiley:


Haha, you don’t say :wink:

I stripped out that part, because it is inrelevant… It comes into the if for sure, it also returns the $check string, but with code 200 instead of 500.


How are you making the client request to that route? What does your http access_log (or equivalent) say for the URI being accessed?


Not that much, I only see this in the access log, is this what you mean?

::1 - - [11/Jul/2017:20:32:35 +0200] "POST /mooddii/api/generate HTTP/1.1" 200 15 ::1 - - [11/Jul/2017:20:32:42 +0200] "OPTIONS * HTTP/1.0" 200


Found it, had a whitespace outside the php tag in one of the files. Deleted it and it works now!


THANK YOU SOOO MUCH! I was about to loose my mind and it was only that single whitespace for me as well