Skip to content

Instantly share code, notes, and snippets.

@kantapp
Created April 21, 2018 06:25
Show Gist options
  • Save kantapp/e4dfabc840ef06ccf615a1725ff6be76 to your computer and use it in GitHub Desktop.
Save kantapp/e4dfabc840ef06ccf615a1725ff6be76 to your computer and use it in GitHub Desktop.
How to get Header in php using Slim Framework
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App;
$app->get('/',function($request,$response,$array)
{
// $headers = apache_request_headers();
// if (isset($headers['Authorization']))
// {
// $api_key = $headers['Authorization'];
// echo $api_key;
// } else {
// $data["error"] = true;
// $data["message"] = "Api key is misssing";
// return $response->withJson($data);
// }
// print_r($request->getserverParams());
// print_r($request->getHeader());
$tokon=$request->getserverParams()["HTTP_KANTAPP_COM"];
if($tokon=='kantapp123456')
{
echo "Welcome to this site";
}
else {
$data["status"]="Error";
$data["message"]="Token is invalid";
return $response->withJson($data,401);
}
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment