diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index f7c2ff27de..16b616a3cb 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -150,6 +150,7 @@ Yii Framework 2 Change Log - Enh: Added support for reading page size from query parameters by `Pagination` (qiangxue) - Enh: LinkPager can now register relational link tags in the html header for prev, next, first and last page (cebe) - Enh: Added `yii\web\UrlRuleInterface` and `yii\web\CompositeUrlRule` (qiangxue) +- Enh: Added `yii\web\Request::getAuthUser()` and `getAuthPassword()` (qiangxue) - Chg #1186: Changed `Sort` to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue) - Chg #1519: `yii\web\User::loginRequired()` now returns the `Response` object instead of exiting the application (qiangxue) - Chg #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default (qiangxue) diff --git a/framework/web/Request.php b/framework/web/Request.php index aafbc04129..ed48401545 100644 --- a/framework/web/Request.php +++ b/framework/web/Request.php @@ -819,6 +819,22 @@ class Request extends \yii\base\Request return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : null; } + /** + * @return string the username sent via HTTP authentication, null if the username is not given + */ + public function getAuthUser() + { + return isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; + } + + /** + * @return string the password sent via HTTP authentication, null if the username is not given + */ + public function getAuthPassword() + { + return isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; + } + private $_port; /**