当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getHeader方法代码示例

本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getHeader方法的具体用法?PHP Request::getHeader怎么用?PHP Request::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\PhpEnvironment\Request的用法示例。


在下文中一共展示了Request::getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setRequest

 /**
  * @param Request $request
  */
 public function setRequest(Request $request)
 {
     $header = $request->getHeader($this->headerName);
     if ($header) {
         $this->requestHeaderValue = $header->getFieldValue();
     }
 }
开发者ID:middleout,项目名称:mdo-bundle-zf2-locale,代码行数:10,代码来源:Header.php

示例2: RequestAreAuthorized

 public static function RequestAreAuthorized()
 {
     $request = new Request();
     $authHeader = $request->getHeader('authorization');
     if ($authHeader) {
         list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
         if ($jwt) {
             try {
                 $secretKey = "CoppinPannequinAudio";
                 JWT::$leeway = 5;
                 $token = JWT::decode($jwt, $secretKey, array('HS512'));
                 return $token;
             } catch (Exception $e) {
                 return false;
             }
             return false;
         }
         return false;
     }
     return false;
 }
开发者ID:CrunchyArtie,项目名称:CoppinPannequinAudio,代码行数:21,代码来源:LoginWebServices.php

示例3: Request

 /**
  * Validates a token.
  *
  * Automatically validates a token when a request has an header with authorization.
  *
  * @since 4.3.0
  *
  * @return int|false user-id when token is valid, false when it is invalid.
  */
 function validate_token()
 {
     $request = new Request();
     if ($request->isGet() || $request->isPost()) {
         $authHeader = $request->getHeader('authorization');
         if ($authHeader) {
             list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
             if ($jwt) {
                 try {
                     $secretKey = base64_decode(get_option('jwt_secret'));
                     $token = JWT::decode($jwt, $secretKey, array('HS256'));
                     return $token->data->userId;
                 } catch (Exception $e) {
                     // FALSE if token is invalid
                     return false;
                 }
             } else {
                 //  FALSE if no token was passed
                 return false;
             }
         }
     }
     return false;
 }
开发者ID:YanikPei,项目名称:wp-jwt-authentication,代码行数:33,代码来源:class-wak-functions.php

示例4: testRetrievingASingleValueForParameters

 public function testRetrievingASingleValueForParameters()
 {
     $request = new Request();
     $p = new \Zend\Stdlib\Parameters(array('foo' => 'bar'));
     $request->setQuery($p);
     $request->setPost($p);
     $request->setFiles($p);
     $request->setServer($p);
     $request->setEnv($p);
     $this->assertSame('bar', $request->getQuery('foo'));
     $this->assertSame('bar', $request->getPost('foo'));
     $this->assertSame('bar', $request->getFiles('foo'));
     $this->assertSame('bar', $request->getServer('foo'));
     $this->assertSame('bar', $request->getEnv('foo'));
     $headers = new Headers();
     $h = new GenericHeader('foo', 'bar');
     $headers->addHeader($h);
     $request->setHeaders($headers);
     $this->assertSame($headers, $request->getHeaders());
     $this->assertSame($h, $request->getHeaders()->get('foo'));
     $this->assertSame($h, $request->getHeader('foo'));
 }
开发者ID:Rovak,项目名称:zf2,代码行数:22,代码来源:RequestTest.php

示例5: Request

<?php

chdir(dirname(__DIR__));
require_once 'vendor/autoload.php';
use Zend\Config\Config;
use Zend\Config\Factory;
use Zend\Http\PhpEnvironment\Request;
/*
 * Get all headers from the HTTP request
 */
$request = new Request();
if ($request->isGet()) {
    $authHeader = $request->getHeader('authorization');
    /*
     * Look for the 'authorization' header
     */
    if ($authHeader) {
        /*
         * Extract the jwt from the Bearer
         */
        list($jwt) = sscanf($authHeader->toString(), 'Authorization: Bearer %s');
        if ($jwt) {
            try {
                $config = Factory::fromFile('config/config.php', true);
                /*
                 * decode the jwt using the key from config
                 */
                $secretKey = base64_decode($config->get('jwt')->get('key'));
                $token = JWT::decode($jwt, $secretKey, [$config->get('jwt')->get('algorithm')]);
                $asset = base64_encode(file_get_contents('http://lorempixel.com/200/300/cats/'));
                /*
开发者ID:Kogonuso,项目名称:sp-simple-jwt,代码行数:31,代码来源:resource.php

示例6: getHeader

 /**
  * Get all headers of a certain name/type.
  *
  * @param string $name Header name to retrieve.
  * @param mixed|null $default Default value to use when the requested header is missing.
  * @return bool|HeaderInterface
  */
 public function getHeader($name, $default = false)
 {
     $header = parent::getHeader($name, $default);
     if ($header instanceof HeaderInterface) {
         return $header->getFieldValue();
     }
     return false;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Request.php


注:本文中的Zend\Http\PhpEnvironment\Request::getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。