Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class authorization {
- public function __invoke($request, $handler): Response {
- $response = new Response();
- if(isset($_SERVER['HTTP_AUTHORIZATION'])){
- list($user_id,$pass)=explode(':',base64_decode($_SERVER['HTTP_AUTHORIZATION']));
- if(is_numeric($user_id)){
- $request=$request->withAttribute('user_id',$user_id);
- return $handler->handle($request);
- }
- }
- return $response->withStatus(403);
- }
- }
- //route
- $param['user_id']=$request->getAttribute('user_id');
- })->add(new authorization());
- SetEnvIf Authorization "Basic (.*)" HTTP_AUTHORIZATION=$1
- RewriteEngine On
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^api index.php [QSA,L,NC]
Add Comment
Please, Sign In to add comment