2017-04-13 65 views
0

我再次遇到同样的问题。标题无法设置 - SlimFramework

旧后here

我有一个角应用和SlimFramework的API连接。

本地它工作正常,但当我发布到我的网站来的错误,我的标题没有设置。 但API测试工具的信息表明它可以来自* IP。

有人可以帮助我吗?

这里有效令牌:基本TyOSZcfBwMC6DR9kbAWeMnPmhF4ohZu2n9LccQEyt6uXNt8PTT

THX

enter image description here

$app = new \Slim\App(["settings" => $config]); 
$container = $app->getContainer(); 
$app->options('/{routes:.+}', function ($request, $response, $args) { 
    return $response; 
}); 
$app->add(function ($req, $res, $next) { 
    $response = $next($req, $res); 
    return $response 
     ->withHeader('Access-Control-Allow-Origin', '*') 
     ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization') 
     ->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, DELETE, PUT'); 
}); 

$container['logger'] = function($c) { 
    $logger = new \Monolog\Logger('my_logger'); 
    $file_handler = new \Monolog\Handler\StreamHandler("../../logs/app.log"); 
    $logger->pushHandler($file_handler); 
    return $logger; 
}; 
$app->get('/token', function ($request, $response){ 
    $db = new DbOperation(); 
    if (!$request->hasHeader('Authorization')) { 
     return $response->withJson([ 
      "success"=> false, 
      "message" => "Header not set.", 
      "textcode"=> "MSG2" 
     ], 401); 
    } 
    $token = $request->getHeader('Authorization'); 

    if($db->checkToken($token[0])){ 
     $user = $db->userInfo($token[0]); 
     if($db->checkActivate($user['auth_user'])){ 
      if($db->checkExpired($user['auth_user'])){ 
       return $response->withJson([ 
        "success"=> false, 
        "message" => "The validity of the login has expired. If you have any questions, please contact the administrator..", 
        "textcode"=> "MSG6" 
       ], 401); 
      } else { 
       return $response->withJson(["success"=> true], 200); 
      } 
     } else { 
      return $response->withJson([ 
       "success"=> false, 
       "message" => "This account has not yet been activated.", 
       "textcode"=> "MSG8" 
      ], 401); 
     } 
    } else { 
     return $response->withJson([ 
      "success"=> false, 
      "message"=>'Invalid token', 
      "textcode"=> "MSG1" 
     ], 403); 
    } 
}); 
+0

请不要将代码包含为图片。它是文本,所以包括它。没有人会从你的图像中复制你的代码并试用它,甚至不会打开图像。 – jmattheis

+0

用curl执行请求,并且经常发现问题。 –

回答

1

你的基本身份验证凭据没有解码成任何有意义的东西。 PHP往往默默地忽略它认为格式不正确的授权标头。尝试使用类似Basic dGVzdDp0ZXN0的解码为test:test的内容。

解决方法为此已添加到从版本3.5.0开始的Slim。升级Slim安装可能也有帮助。

+0

Thx。我使用'''Setenvif授权^(。+)$ auth_head = $ 1'''和'''getenv(“auth_head”)来解决它''' – Neonlight