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


PHP Request::header方法代码示例

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


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

示例1: facebook

 public function facebook(Request $request)
 {
     $accessTokenUrl = 'https://graph.facebook.com/v2.5/oauth/access_token';
     $graphApiUrl = 'https://graph.facebook.com/v2.5/me';
     $params = ['code' => $request->input('code'), 'client_id' => $request->input('clientId'), 'redirect_uri' => $request->input('redirectUri'), 'client_secret' => '76cd1014c10586c33f3e13f03929a221'];
     $client = new \GuzzleHttp\Client();
     // Step 1. Exchange authorization code for access token.
     $accessToken = json_decode($client->get($accessTokenUrl, ['query' => $params])->getBody(), true);
     // Step 2. Retrieve profile information about the current user.
     $profile = json_decode($client->get($graphApiUrl, ['query' => $accessToken])->getBody(), true);
     // Step 3a. If user is already signed in then link accounts.
     if ($request->header('Authorization')) {
         $user = User::where('facebook', '=', $profile['id']);
         if ($user->first()) {
             return response()->json(['message' => 'There is already a Facebook account that belongs to you'], 409);
         }
         $token = explode(' ', $request->header('Authorization'))[1];
         $payload = (array) JWT::decode($token, Config::get('jwt.secret'), array('HS256'));
         $user = User::find($payload['sub']);
         $user->facebook = $profile['id'];
         $user->displayName = $user->displayName ?: $profile['name'];
         $user->save();
         return response()->json(['token' => $this->createToken($user)]);
     } else {
         $user = User::where('facebook', '=', $profile['id']);
         if ($user->first()) {
             return response()->json(['token' => $this->createToken($user->first())]);
         }
         $user = new User();
         $user->facebook = $profile['id'];
         $user->displayName = $profile['name'];
         $user->save();
         return response()->json(['token' => $this->createToken($user)]);
     }
 }
开发者ID:theprog,项目名称:election-hacakthon-cityzen,代码行数:35,代码来源:AuthenticateController.php

示例2: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $jwt = $request->header('x-auth-jwt');
     $key = 'fad';
     //env('JWT_KEY');
     $decoded = JWT::decode($jwt, $key, array('HS256'));
     /*
     	
     /*
      		NOTE: This will now be an object instead of an associative array. To get
      		an associative array, you will need to cast it as such:
     */
     //$decoded_array = (array) $jwt;
     /**
      * You can add a leeway to account for when there is a clock skew times between
      * the signing and verifying servers. It is recommended that this leeway should
      * not be bigger than a few minutes.
      *
      * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
      */
     //JWT::$leeway = 60; // $leeway in seconds
     //$decoded = JWT::decode($jwt, $key, array('HS256'));
     return $next($request);
     //$res = $next($request);
     //echo "after http request!";
     //return $res;
 }
开发者ID:xzungshao,项目名称:lar5-one,代码行数:34,代码来源:JwtMiddleware.php

示例3: checkRequest

 /**
  * Check the request headers.
  *
  * @param  Illuminate\Http\Request $request
  * @return void
  */
 protected function checkRequest(Request $request)
 {
     $this->checkAcceptHeader($request->header('accept'));
     if (!in_array($request->method(), ['GET', 'OPTIONS'])) {
         $this->checkContentTypeHeader($request->header('content-type'));
     }
 }
开发者ID:devdk,项目名称:signy,代码行数:13,代码来源:JsonApi.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $access_token = $request->header('access_token');
     $refresh_token = $request->header('refresh_token');
     if ($access_token == null && $refresh_token == null) {
         return response('No Token', 400);
     } else {
         $verifyAccess = UserTokenModel::find($access_token);
         $verifyRefresh = UserRefreshTokenModel::find($refresh_token);
         $current_time = time();
         //            echo(strtotime($verifyAccess->expires)-$current_time .'<br>');
         //            echo($current_time);
         //            echo(((strtotime($verifyAccess->expires)-$current_time)<3600)."<br>");
         //            echo((strtotime($verifyRefresh->expires)-$current_time));
         if (count($verifyAccess) > 0) {
             if (strtotime($verifyAccess->expires) > $current_time) {
                 return $next($request);
             } else {
                 return response()->json(['message' => 'Token expired'], 403);
             }
         } else {
             return response()->json(['message' => 'Invalid token'], 403);
         }
     }
 }
开发者ID:Insantani,项目名称:SourceTree-diovi,代码行数:32,代码来源:ShoppingCartMiddleware.php

示例5: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $token = $request->header('access-token');
     $token = isset($token) ? $request->header('access-token') : $request->get('api_token');
     if (!$token) {
         return response('Unauthorized.', 403);
     }
     $key = getenv('APP_KEY');
     $signer = new Sha256();
     $data = new ValidationData();
     // It will use the current time to validate (iat, nbf and exp)
     $data->setIssuer($request->server('REMOTE_ADDR'));
     $data->setAudience($request->server('HTTP_HOST'));
     try {
         $token = (new Parser())->parse((string) $token);
         if (!$token->validate($data)) {
             return response('Unauthorized data', 401);
         }
         if (!$token->verify($signer, $key)) {
             return response('Unauthorized sign', 401);
         }
         putenv("USER=" . $token->getClaim('uid'));
         return $next($request);
     } catch (\Exception $e) {
         return response('Unauthorized: ' . $e->getMessage(), 403);
     }
 }
开发者ID:brenodouglas,项目名称:lumenjwt-example,代码行数:34,代码来源:JwtAuthMiddleware.php

示例6: __construct

 public function __construct(Request $request)
 {
     if (!$request->header('App-token')) {
         exit;
     }
     $this->user_id = TokenService::tokenDecrypt($request->header('App-token'));
 }
开发者ID:xiongjiewu,项目名称:shui,代码行数:7,代码来源:BaseController.php

示例7: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->agent->isRobot() || $request->header('user-agent') == '' || !$request->header('user-agent')) {
         return redirect($_SERVER['HTTP_REFERER']);
     }
     return $next($request);
 }
开发者ID:henrytung,项目名称:Bodie-CRM,代码行数:14,代码来源:SpamMiddleware.php

示例8: getToken

 /**
  * Get OTP Session Token.
  *
  * @return string|exception
  */
 protected function getToken()
 {
     if (!$this->request->hasHeader('X-OTP-SESSION-TOKEN')) {
         throw new InvalidTwoFactorSessionToken();
     }
     return $this->request->header('X-OTP-SESSION-TOKEN');
 }
开发者ID:devdk,项目名称:signy,代码行数:12,代码来源:TwoFactor.php

示例9: saveFranchise

 public function saveFranchise(Request $request)
 {
     /*        $validator = Validator::make($request->all(), [
                 'jenis'         => 'required|integer',
                 'namausaha'     => 'required|unique:franchises',
                 'telepon'       => 'required',
                 'alamat'        => 'required|max:50'
             ]);
             if ($validator->fails()) {
                 $message = $validator->errors();
                 return $this->httpUnprocessableEntity($message);
             }
             $jenis      = $request->input('jenis');
             $namausaha  = $request->input('namausaha');
             $telepon    = $request->input('telepon');
             $alamat     = $request->input('alamat');
             $image      = $request->input('logo');
     */
     $validator = Validator::make($request->all(), ['logo' => 'image|mimes:jpg,jpeg,png|max:2000']);
     if ($validator->fails()) {
         $message = $validator->errors();
         return $this->httpUnprocessableEntity($message);
     }
     $jenis = $request->header('jenis');
     $namausaha = $request->header('namausaha');
     $telepon = $request->header('telepon');
     $alamat = $request->header('alamat');
     $image = $request->file('logo');
     $cek = Jenis::where('id', $jenis)->first();
     if (empty($cek)) {
         return $this->httpUnprocessableEntity('Id jenis tidak valid');
     }
     $db = new Franchise();
     $db->jenis = $jenis;
     $db->namausaha = $namausaha;
     $db->franchisor_id = $this->userID($request);
     $franchisor = new Franchisor();
     $franchisor->where('id', $this->userID($request))->update(['alamat' => $alamat, 'telepon' => $telepon]);
     if ($image) {
         //$image ='data:image/jpeg;base64,' .base64_encode($image);
         /*header("Content-type: image/jpeg");
           $image = Image::make($image);
           $image = $image->response('jpg', 70);*/
         $salt = hash('sha256', time() . mt_rand());
         $link = substr($salt, 0, 40) . ".png";
         $resizedImage = $this->resize($image, 500, 500, $link);
         if (!$resizedImage) {
             return response()->json(['status' => false, 'msg' => 'gagal'], 204);
         }
         $db->logo = $link;
         $db->logo_url = url('api/logo/' . $link);
     }
     $db->logo = "avatar.png";
     $db->logo_url = url('api/logo/avatar.png');
     if ($db->save()) {
         return $this->httpCreate();
     }
     return $this->httpServerError();
 }
开发者ID:tofa17,项目名称:posmikro,代码行数:59,代码来源:FranchiseController.php

示例10: tokensMatch

 /**
  * Determine if the session and input CSRF tokens match.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return bool
  */
 protected function tokensMatch($request)
 {
     $token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
     if (!$token && ($header = $request->header('X-XSRF-TOKEN'))) {
         $token = $this->encrypter->decrypt($header);
     }
     return Str::equals($request->session()->token(), $token);
 }
开发者ID:alvarobfdev,项目名称:LaravelCore,代码行数:14,代码来源:VerifyCsrfToken.php

示例11: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->user->authenticateApiV1($request->header('Authorization')) !== false) {
         $this->auth->loginUsingId($this->user->authenticateApiV1($request->header('Authorization')));
     } else {
         return response('Invalid API token.', 401);
     }
     return $next($request);
 }
开发者ID:kz,项目名称:timetable-pusher-backend,代码行数:16,代码来源:AuthenticateApiV1.php

示例12: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!empty($request->header('credential'))) {
         if (Credential::where('key', $request->header('credential'))->count() != 0) {
             return $next($request);
         }
     }
     $this->response->error('Not Valid Api Credential', 500);
 }
开发者ID:masmike,项目名称:scafolding,代码行数:16,代码来源:Credentials.php

示例13: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $cookieLang = Cookie::get('i18next');
     if ($cookieLang) {
         App::setLocale($cookieLang);
     } elseif ($request->header('Accept-Language')) {
         App::setLocale($request->header('Accept-Language'));
     }
     return $next($request);
 }
开发者ID:a1ex7,项目名称:asciit,代码行数:17,代码来源:DetectLocale.php

示例14: validateRequest

 public function validateRequest(Request $request)
 {
     if ($request->header('Accept') != JsonApi::MIME_TYPE) {
         throw new \RuntimeException('Invalid Accept header.');
     }
     if (!empty($request->getContent()) && $request->header('Content-Type') != JsonApi::MIME_TYPE) {
         throw new \RuntimeException('Invalid Content-Type header.');
     }
     return true;
 }
开发者ID:marius321967,项目名称:lumen-jsonapi,代码行数:10,代码来源:Validator.php

示例15: create

 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function create(Request $request)
 {
     $message['to'] = $request->input('to');
     $message['from'] = $request->input('from');
     $message['body'] = $request->input('body');
     $message['accountSid'] = $request->header('X-TWILIO-ACCOUNT-SID');
     $message['authToken'] = $request->header('X-TWILIO-AUTH-TOKEN');
     $client = new \Services_Twilio($message['accountSid'], $message['authToken']);
     $client->account->messages->create(['To' => $message['to'], 'From' => $message['from'], 'Body' => $message['body']]);
     exit;
 }
开发者ID:texxt,项目名称:api,代码行数:16,代码来源:MessageController.php


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