Skip to content

Instantly share code, notes, and snippets.

@Matheus-de-Souza
Last active April 2, 2018 14:49
Show Gist options
  • Save Matheus-de-Souza/41de8d5226765b9d4eb2ca39ed199e4a to your computer and use it in GitHub Desktop.
Save Matheus-de-Souza/41de8d5226765b9d4eb2ca39ed199e4a to your computer and use it in GitHub Desktop.
<?php
$app->hook('slim.before.router', function () use ($app) {
$api_key = $app->request->headers('Api-Key');
if ($api_key == '' && strlen($app->request->getBody()) == 0 ) {
$app->halt(200, '"CORS OK"');
} else {
$valid_api_key = $_SESSION["Config"]["API"]["API_KEY"];
if (strcmp($api_key, $valid_api_key) != 0) {
$result = array ();
$result['Mensagem'] = "Houve um erro na requisição. Api-Key inválida.";
$app->halt(401, json_encode($result));
}
}
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment