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


PHP Request::server方法代码示例

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


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

示例1: negotiateLanguage

 /**
  * Negotiates language with the user's browser through the Accept-Language
  * HTTP header or the user's host address.  Language codes are generally in
  * the form "ll" for a language spoken in only one country, or "ll-CC" for a
  * language spoken in a particular country.  For example, U.S. English is
  * "en-US", while British English is "en-UK".  Portuguese as spoken in
  * Portugal is "pt-PT", while Brazilian Portuguese is "pt-BR".
  *
  * This function is based on negotiateLanguage from Pear HTTP2
  * http://pear.php.net/package/HTTP2/
  *
  * Quality factors in the Accept-Language: header are supported, e.g.:
  *      Accept-Language: en-UK;q=0.7, en-US;q=0.6, no, dk;q=0.8
  *
  * @return string  The negotiated language result or app.locale.
  */
 public function negotiateLanguage()
 {
     $matches = $this->getMatchesFromAcceptedLanguages();
     foreach ($matches as $key => $q) {
         if (!empty($this->supportedLanguages[$key])) {
             return $key;
         }
     }
     // If any (i.e. "*") is acceptable, return the first supported format
     if (isset($matches['*'])) {
         reset($this->supportedLanguages);
         return key($this->supportedLanguages);
     }
     if (class_exists('Locale') && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $http_accept_language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
         if (!empty($this->supportedLanguages[$http_accept_language])) {
             return $http_accept_language;
         }
     }
     if ($this->request->server('REMOTE_HOST')) {
         $remote_host = explode('.', $this->request->server('REMOTE_HOST'));
         $lang = strtolower(end($remote_host));
         if (!empty($this->supportedLanguages[$lang])) {
             return $lang;
         }
     }
     return $this->defaultLocale;
 }
开发者ID:Syrok,项目名称:laravel-localization,代码行数:44,代码来源:LanguageNegotiator.php

示例2: 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

示例3: getHeaderAcceptedLocales

 /**
  * Return a list of accept locale from the HTTP.
  *
  * @throws \Hpkns\I18n\Exceptions\EmptyAcceptHeader
  * @return array
  */
 public function getHeaderAcceptedLocales()
 {
     $accepted = $this->request->server('HTTP_ACCEPT_LANGUAGE');
     if (empty($accepted)) {
         throw new Exceptions\EmptyAcceptHeader('HTTP Accept header empty or not found');
     }
     return explode(',', $accepted);
 }
开发者ID:hpkns,项目名称:laravel-i18n,代码行数:14,代码来源:LocaleManager.php

示例4: authenticate

 public function authenticate(Request $request)
 {
     $credentials = $request->json()->all();
     if (!($user = Auth::attempt($credentials, $request->has('remember')))) {
         return false;
     }
     $user = Auth::user();
     $key = getenv('APP_KEY');
     $signer = new Sha256();
     $token = (new Builder())->setIssuer($request->server('REMOTE_ADDR'))->setAudience($request->server('HTTP_HOST'))->setIssuedAt(time())->setNotBefore(time())->setExpiration(time() + 3600)->set('uid', $user->id)->sign($signer, $key)->getToken();
     return $token->__toString();
 }
开发者ID:brenodouglas,项目名称:lumenjwt-example,代码行数:12,代码来源:Service.php

示例5: resolveHeader

 /**
  * Resolve language using HTTP_ACCEPT_LANGUAGE header
  * which is used mostly by API requests
  *
  * @return array|null
  */
 private function resolveHeader()
 {
     if (null === static::$languages) {
         $httpLanguages = $this->request->server(config('localizer.request.header', 'HTTP_ACCEPT_LANGUAGE'));
         if (empty($httpLanguages)) {
             static::$languages = [];
         } else {
             $accepted = preg_split('/,\\s*/', $httpLanguages);
             static::$languages = empty($languages = $this->buildCollection($accepted, $languages = [])) ? null : array_keys($languages)[0];
         }
     }
     return static::$languages;
 }
开发者ID:adminarchitect,项目名称:localizer,代码行数:19,代码来源:RequestResolver.php

示例6: appKeyAvailable

 /**
  * Check if there is any problem with the app key
  *
  * @param Request $request
  * @return Response
  */
 protected function appKeyAvailable($request)
 {
     $app_key = getenv('APP_KEY');
     if (empty($app_key)) {
         return false;
     }
     if (empty($request->server()['HTTP_X_APP_KEY'])) {
         return false;
     }
     if ($app_key != $request->server()['HTTP_X_APP_KEY']) {
         return false;
     }
     return true;
 }
开发者ID:Baasify,项目名称:Baasify,代码行数:20,代码来源:MainController.php

示例7: authenticate

 public function authenticate(Request $request)
 {
     $credentials = $request->json()->all();
     if (!($user = Auth::attempt($credentials, $request->has('remember')))) {
         return false;
     }
     $user = Auth::user();
     $key = config('jwt.key');
     $signer = new Sha256();
     $builder = (new Builder())->setIssuer(config('jwt.host'))->set('uid', $user->id);
     if (config('jwt.payload')['aud']) {
         $builder->setAudience($request->server('REMOTE_ADDR'));
     }
     if (config('jwt.payload')['iss']) {
         $builder->setIssuedAt(time());
     }
     if (config('jwt.payload')['nbf']) {
         $builder->setNotBefore(time() + config('jwt.not_before_time'));
     }
     if (config('jwt.payload')['exp']) {
         $builder->setExpiration(time() + config('jwt.expires'));
     }
     $token = $builder->sign($signer, $key)->getToken();
     return $token->__toString();
 }
开发者ID:brenodouglas,项目名称:laraveljwt,代码行数:25,代码来源:JwtAuth.php

示例8: unauthorized

 public function unauthorized(Request $request)
 {
     if (!$request->server('HTTP_REFERER')) {
         return redirect('/home');
     }
     return view('pages.unauthorized');
 }
开发者ID:poppabear8883,项目名称:WebEgg,代码行数:7,代码来源:SiteController.php

示例9: handle

 /**
  * Handle an incoming request.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     // If the user is already logged in, we don't need to reauthenticate.
     if (!$this->auth->check()) {
         // Retrieve the SSO login attribute.
         $auth = $this->getWindowsAuthAttribute();
         // Retrieve the SSO input key.
         $key = key($auth);
         // Handle Windows Authentication.
         if ($account = $request->server($auth[$key])) {
             // Usernames may be prefixed with their domain,
             // we just need their account name.
             $username = explode('\\', $account);
             if (count($username) === 2) {
                 list($domain, $username) = $username;
             } else {
                 $username = $username[key($username)];
             }
             // Create a new user LDAP user query.
             $query = $this->newAdldapUserQuery();
             // Filter the query by the username attribute
             $query->whereEquals($key, $username);
             // Retrieve the first user result
             $user = $query->first();
             if ($user instanceof User) {
                 $model = $this->getModelFromAdldap($user, str_random());
                 if ($model instanceof Model) {
                     // Double check user instance before logging them in.
                     $this->auth->login($model);
                 }
             }
         }
     }
     return $this->returnNextRequest($request, $next);
 }
开发者ID:minkbear,项目名称:Adldap2-Laravel,代码行数:43,代码来源:WindowsAuthenticate.php

示例10: handle

 /**
  * @param \Illuminate\Http\Request $request
  * @param \Closure $next
  * @return mixed
  * @throws \Illuminate\Http\Exception\PostTooLargeException
  */
 public function handle($request, Closure $next)
 {
     if ($request->server('CONTENT_LENGTH') > $this->getPostMaxSize()) {
         throw new PostTooLargeException();
     }
     return $next($request);
 }
开发者ID:darrengopower,项目名称:framework,代码行数:13,代码来源:VerifyPostSize.php

示例11: setupLayout

 protected function setupLayout()
 {
     $is_rapyd = (Request::server('HTTP_HOST') == "www.rapyd.com") ? true : false;
     View::composer('rapyd::demo.*', function ($view) use ($is_rapyd) {
         $view->with('is_rapyd', $is_rapyd);
     });
 }
开发者ID:simplylouis,项目名称:online_book_shop_20151110_laravel_5,代码行数:7,代码来源:DemoController.php

示例12: index

 public function index(Request $request)
 {
     $languages = RefMapper::type('language');
     $bannerTypes = RefMapper::type('banner_type');
     $games = RefMapper::type('game');
     $user = $this->user;
     if ($user->language_id == 0) {
         $userAgentLanguage = $request->server('HTTP_ACCEPT_LANGUAGE');
         $user->language_id = 4;
         if (strpos($userAgentLanguage, 'ru') === 0) {
             $user->language_id = 5;
         }
         if (strpos($userAgentLanguage, 'es') === 0) {
             $user->language_id = 6;
         }
         $user->save();
     }
     if (count($user->bannerTypes()->get()) == 0) {
         foreach ($bannerTypes as $bannerType) {
             $user->refs()->attach($bannerType->id);
         }
         $user->save();
     }
     return view('app.pages.user.twitcher.profile.index', compact('languages', 'bannerTypes', 'games', 'user'));
 }
开发者ID:blozixdextr,项目名称:adtw,代码行数:25,代码来源:ProfileController.php

示例13: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $subject = ObjectFinder::GetObject($request->subject_type, $request->subject_id);
     $subject->RecordNewComment($request->comment);
     flash()->success('Success', "New Comment created successfully");
     return redirect($request->server('HTTP_REFERER'));
 }
开发者ID:SlipperyPenguine,项目名称:tracker,代码行数:13,代码来源:CommentController.php

示例14: isValidRequest

 /**
  * Validate the github payload and signature.
  *
  * If you're wondering why the md5, see the link below.
  * @see http://php.net/manual/en/function.hash-hmac.php#111435
  *
  * @param \Illuminate\Http\Request $request
  * @return bool
  */
 private function isValidRequest($request)
 {
     $signature = $request->server('HTTP_X_HUB_SIGNATURE');
     $secret = env('WEBHOOK_SECRET');
     list($algo, $expectedHash) = explode('=', $signature, 2);
     $payloadHash = hash_hmac($algo, $request->getContent(), $secret);
     return md5($expectedHash) === md5($payloadHash);
 }
开发者ID:flashtag,项目名称:subsplit-service,代码行数:17,代码来源:GithubWebhookMiddleware.php

示例15: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $language = $request->server('HTTP_ACCEPT_LANGUAGE');
     if (starts_with($language, 'zh-CN')) {
         config(['app.locale' => 'zh-CN', 'timezone' => 'Asia/Shanghai']);
     }
     return $next($request);
 }
开发者ID:angelWendy,项目名称:streamlet,代码行数:15,代码来源:SwitchLang.php


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