本文整理汇总了PHP中Magento\Framework\App\RequestInterface::getServerValue方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getServerValue方法的具体用法?PHP RequestInterface::getServerValue怎么用?PHP RequestInterface::getServerValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getServerValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCredentials
/**
* Extract "login" and "password" credentials from HTTP-request
*
* Returns plain array with 2 items: login and password respectively
*
* @return array
*/
public function getCredentials()
{
$server = $this->request->getServerValue();
$user = '';
$pass = '';
if (empty($server['HTTP_AUTHORIZATION'])) {
foreach ($server as $k => $v) {
if (substr($k, -18) === 'HTTP_AUTHORIZATION' && !empty($v)) {
$server['HTTP_AUTHORIZATION'] = $v;
break;
}
}
}
if (isset($server['PHP_AUTH_USER']) && isset($server['PHP_AUTH_PW'])) {
$user = $server['PHP_AUTH_USER'];
$pass = $server['PHP_AUTH_PW'];
} elseif (!empty($server['HTTP_AUTHORIZATION'])) {
/**
* IIS Note: for HTTP authentication to work with IIS,
* the PHP directive cgi.rfc2616_headers must be set to 0 (the default value).
*/
$auth = $server['HTTP_AUTHORIZATION'];
list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
} elseif (!empty($server['Authorization'])) {
$auth = $server['Authorization'];
list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
}
return [$user, $pass];
}