Last active
April 2, 2018 14:49
-
-
Save Matheus-de-Souza/41de8d5226765b9d4eb2ca39ed199e4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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