Slim php, stop, die after sending a 403 response status code in a small middleware -



Slim php, stop, die after sending a 403 response status code in a small middleware -

i created little middleware function slim php framework checks if user authenticated or not, so.

function authenticate($app) { homecoming function() utilize ($app) { if (!isset($_session['user'])) { $response = array(); array_push($response, array( 'error' => true, 'message' => 'you not logged in.' ) ); echores(403, $response); } }; }

what happens if tried insert in route this:

$app->get('/', authenticate($app), function() utilize ($app){ echores(200, 'hello world!'); });

the echores function

function echores($code, $response) { $app = \slim\slim::getinstance(); $app->status($code); $app->contenttype('application/json'); echo json_encode($response); }

what happens go on give me status code of 200 when not authenticated, kill using die();

function authenticate($app) { homecoming function() utilize ($app) { if (!isset($_session['user'])) { $response = array(); array_push($response, array( 'error' => true, 'message' => 'you not logged in.' ) ); echores(403, $response); die(); } }; }

i utilize $app->notfound() or $app->halt(403) halt execution. there no need set status code set these functions.

php slim

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -