duanou8504 2016-12-03 07:36
浏览 42
已采纳

如何从Symfony的HttpFoundation组件中检索基本身份验证凭据?

I want to retrieve the basic authentication credentials from Symfony's HttpFoundation component. A cursory look at the docs reveals nothing; is there a way I can do it?

(I'm using the HttpFoundation component in an application not based on the Symfony framework.)

  • 写回答

1条回答 默认 最新

  • duanpanbo9476 2016-12-04 04:18
    关注

    The values of $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] can be accessed through an instance of Symfony\Component\HttpFoundation\Request in the following manner:

    $username = $request->headers->get('php-auth-user');
    $password = $request->headers->get('php-auth-pw');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?