當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ServerRequestInterface::getIp方法代碼示例

本文整理匯總了PHP中Psr\Http\Message\ServerRequestInterface::getIp方法的典型用法代碼示例。如果您正苦於以下問題:PHP ServerRequestInterface::getIp方法的具體用法?PHP ServerRequestInterface::getIp怎麽用?PHP ServerRequestInterface::getIp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Psr\Http\Message\ServerRequestInterface的用法示例。


在下文中一共展示了ServerRequestInterface::getIp方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __invoke

 /**
  * IP Restriction Middleware call.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request 
  *   PSR7 request
  * @param \Psr\Http\Message\ResponseInterface $response
  *   PSR7 response
  * @param callable $next 
  *   Next middleware
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
 {
     // Get client's IP.
     $ip = $request->getIp();
     // Get the Content-Type set in the Request's Accept header.
     $contentType = $this->determineContentType($request->getHeaderLine('Accept'));
     // Desired status code to send.
     $statusCode = $this->setStatusCode($this->options);
     // Exception Message to send.
     $message = $this->setExceptionMessage($contentType, $this->options);
     // Restrict The IP access if needed.
     $restrict = $this->restrict($ip, $this->allowList, !$this->negate);
     if ($restrict === true) {
         return $response->withStatus($statusCode)->withHeader('Content-type', $contentType)->write($message);
     } else {
         // Proceed with the application access.
         return $response = $next($request, $response);
     }
 }
開發者ID:aneek,項目名稱:slim-ip-restrict,代碼行數:31,代碼來源:IpRestrictMiddleware.php


注:本文中的Psr\Http\Message\ServerRequestInterface::getIp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。