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


PHP Request::getClientIp方法代码示例

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


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

示例1: matches

 public function matches(Request $request)
 {
     if (!$this->language) {
         throw new \LogicException('Unable to match the request as the expression language is not available.');
     }
     return $this->language->evaluate($this->expression, array('request' => $request, 'method' => $request->getMethod(), 'path' => rawurldecode($request->getPathInfo()), 'host' => $request->getHost(), 'ip' => $request->getClientIp(), 'attributes' => $request->attributes->all())) && parent::matches($request);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:ExpressionRequestMatcher.php

示例2: doExecute

 /**
  * Executes the action with the given context.
  *
  * @param string $ip
  *   (optional) The IP address that should be banned.
  */
 public function doExecute($ip = NULL)
 {
     if (!isset($ip)) {
         $ip = $this->request->getClientIp();
     }
     $this->banManager->banIp($ip);
 }
开发者ID:shahinam,项目名称:drupal8devel,代码行数:13,代码来源:BanIP.php

示例3: getVisitasForViewAction

 /**
  * Sistema de almacenamiento de entradas a la pagina para reflejar el numero
  * de visitas.
  */
 public function getVisitasForViewAction(Request $req)
 {
     //Grabamos la visita en la BD
     $sess = $this->container->get('session');
     $now = array('ip' => $req->getClientIp(), 'visitas' => 0);
     if ($sess->has('visitas')) {
         $now = json_decode($sess->get('visitas'), TRUE);
         if ($req->getClientIp() == $now['ip']) {
             goto retorno;
         }
     }
     $em = $this->getDoctrine()->getManager();
     $visitas = $em->getRepository('AppBundle:Visitas')->findAll();
     if (count($visitas) == 0) {
         $visitas = new \AppBundle\Entity\Visitas();
         $visitas->setVisitas(1);
         goto lleno;
     }
     if (count($visitas) > 0) {
         $visitas = $visitas[0];
         $visitas->setVisitas($visitas->getVisitas() + 1);
     }
     lleno:
     $visitas->setIp($req->getClientIp());
     $visitas->setUpdated(new \DateTime('now'));
     $now['visitas'] = $visitas->getVisitas();
     $sess->set('visitas', json_encode($now));
     $em->persist($visitas);
     $em->flush();
     retorno:
     return $this->render('::/front/includes/visitas.html.twig', array('visitas' => $now['visitas']));
 }
开发者ID:aldogdl,项目名称:soj,代码行数:36,代码来源:DoorController.php

示例4: __construct

 /**
  * @param LoggerInterface $logger
  * @param Request         $request
  * @param array           $options
  */
 public function __construct(LoggerInterface $logger, Request $request, array $options = array())
 {
     $this->logger = $logger;
     $this->options = $this->configureOptions($options);
     $this->request = $request;
     $this->logger->debug('Create call with params ' . json_encode($this->options));
     $this->logger->debug('Request server values: ' . json_encode($this->request->server));
     $this->host = $this->request->getClientIp();
     $queryBag = $this->request->query;
     $this->securityCode = $queryBag->has('securityCodeFieldName') ? $queryBag->get('securityCodeFieldName') : '';
     $body = $this->request->getContent();
     if (!$body) {
         $this->logger->error('Event content is null');
         $this->valid = false;
         return;
     }
     $this->logger->debug('Event content: ' . $body);
     try {
         $json = json_decode($body, true);
     } catch (\Exception $e) {
         $this->logger->error('Exception on decode json text');
         $this->valid = false;
     }
     if (!isset($json['ref'])) {
         $this->valid = false;
         return;
     }
     $count = count($json['commits']) - 1;
     $this->author = $json['commits'][$count]['author']['email'];
     $this->authorName = $json['commits'][$count]['author']['name'];
     $this->message = $json['commits'][$count]['message'];
     $this->timestamp = $json['commits'][$count]['timestamp'];
     $this->repository = $json['repository'][$this->options['repositoryFieldName']];
     $this->branch = substr($json['ref'], strrpos($json['ref'], '/') + 1);
 }
开发者ID:amaxlab,项目名称:git-web-hook,代码行数:40,代码来源:Event.php

示例5: getClientIpAddress

 /**
  * Returns the client IP address, try to find
  *
  * @param Request $request
  * @return string
  */
 protected function getClientIpAddress(Request $request)
 {
     $clientIP = $request->getClientIp(true);
     if (empty($clientIP)) {
         $clientIP = $request->getClientIp(false);
     }
     return $clientIP;
 }
开发者ID:niborb,项目名称:appmon,代码行数:14,代码来源:RequestListener.php

示例6: getImage

 /**
  * @param string $email
  * @param string $size
  * @param string $default
  *
  * @return string
  */
 public function getImage($email, $size = '250', $default = null)
 {
     $localDefault = $this->devMode || in_array($this->request->getClientIp(), array_merge($this->devHosts, ['127.0.0.1', 'fe80::1', '::1'])) ? 'https://www.mautic.org/media/images/default_avatar.png' : $this->avatarHelper->getDefaultAvatar(true);
     $url = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=' . $size;
     if ($default === null) {
         $default = $localDefault;
     }
     $default = strpos($default, '.') !== false && strpos($default, 'http') !== 0 ? UrlHelper::rel2abs($default) : $default;
     $url .= '&d=' . urlencode($default);
     return $url;
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:18,代码来源:GravatarHelper.php

示例7: onSessionAccessEvent

 /**
  * @param SessionAccess $event
  */
 public function onSessionAccessEvent(SessionAccess $event)
 {
     $user = $event->getUser();
     $course = $event->getCourse();
     $session = $event->getSession();
     $ip = $this->request->getClientIp();
     $access = new TrackECourseAccess();
     $access->setCId($course->getId())->setUserId($user->getId())->setSessionId($session->getId())->setUserIp($ip);
     $this->em->persist($access);
     $this->em->flush();
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:14,代码来源:SessionAccessListener.php

示例8: onAuthenticationFailure

 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $login = new \Club\UserBundle\Entity\LoginAttempt();
     $login->setUsername($request->get('_username'));
     $login->setSession($request->getSession()->getId());
     $login->setIpAddress($request->getClientIp());
     $login->setHostname(gethostbyaddr($request->getClientIp()));
     $login->setLoginFailed(1);
     $this->em->persist($login);
     $this->em->flush();
     return new RedirectResponse('login');
 }
开发者ID:miteshchavada,项目名称:clubmaster,代码行数:12,代码来源:FailurePasswordHandler.php

示例9: onAuthenticationSuccess

 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $login = new \Club\UserBundle\Entity\LoginAttempt();
     $login->setUsername($request->get('_username'));
     $login->setSession($request->getSession()->getId());
     $login->setIpAddress($request->getClientIp());
     $login->setHostname(gethostbyaddr($request->getClientIp()));
     $login->setLoginFailed(0);
     $this->em->persist($login);
     $this->em->flush();
     return new RedirectResponse('user');
 }
开发者ID:hollodk,项目名称:clubmaster,代码行数:12,代码来源:SuccessPasswordHandler.php

示例10: vote

 /**
  * {@inheritodc}
  */
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     foreach ($attributes as $attribute) {
         if (!$this->supportsAttribute($attribute)) {
             continue;
         }
         if (in_array($this->request->getClientIp(), $this->whitelisted)) {
             return VoterInterface::ACCESS_GRANTED;
         }
         return VoterInterface::ACCESS_DENIED;
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }
开发者ID:Onneil,项目名称:dedipanel,代码行数:16,代码来源:InstallerVoter.php

示例11: onKernelRequest

 /**
  * Set the username from the security context by listening on core.request
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (null === $this->request) {
         return;
     }
     // If you use a cache like Varnish, you may want to set a proxy to Request::getClientIp() method
     // $this->request->setTrustedProxies(array('127.0.0.1'));
     // $ip = $_SERVER['REMOTE_ADDR'];
     $ip = $this->request->getClientIp();
     if (null !== $ip) {
         $this->ipTraceableListener->setIpValue($ip);
     }
 }
开发者ID:sghribi,项目名称:colocs,代码行数:18,代码来源:IpTraceSubscriber.php

示例12: testBuffer

 public function testBuffer()
 {
     $logger = $this->getLogger(['buffer' => true, 'level' => \Psr\Log\LogLevel::ERROR]);
     $message = 'TEst MeSSage';
     $level = \Psr\Log\LogLevel::EMERGENCY;
     $message2 = 'TEst2 MeSSage2';
     $level2 = \Psr\Log\LogLevel::CRITICAL;
     $fullMsg = join(PHP_EOL, [join("\t", [date('c'), $this->request->getClientIp(), $level, $message]), join("\t", [date('c'), $this->request->getClientIp(), $level2, $message2])]);
     $this->storage->expects($this->once())->method('store')->with($fullMsg);
     $logger->emergency($message);
     $logger->critical($message2);
     $logger->flushBuffer();
 }
开发者ID:jakulov,项目名称:corpuscle_log,代码行数:13,代码来源:LoggerTest.php

示例13: validate

 /**
  * Checks if the passed value is valid.
  *
  * @param mixed $value The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  *
  * @api
  */
 public function validate($value, Constraint $constraint)
 {
     $reCaptchaResponse = $this->request->request->get('g-recaptcha-response');
     if (empty($reCaptchaResponse)) {
         $this->context->addViolation($constraint->message);
         return;
     }
     $response = $this->buzz->submit('https://www.google.com/recaptcha/api/siteverify', ['secret' => $this->secret, 'response' => $reCaptchaResponse, 'remoteip' => $this->request->getClientIp()]);
     $reCaptchaValidationResponse = json_decode($response->getContent());
     if (true !== $reCaptchaValidationResponse->success) {
         $this->context->addViolation($constraint->message);
     }
 }
开发者ID:alienpham,项目名称:portfolio,代码行数:21,代码来源:ValidCaptchaValidator.php

示例14: opcacheClearAction

 /**
  * @Route("/opcache-clear/{version}/", name="_enuygun_com_opcache_clear")
  * @param Request $request
  * @param $version
  * @return array
  */
 public function opcacheClearAction(Request $request, $version)
 {
     $ipFilter = $this->container->getParameter('enuygun_com_opcache_clear.ip_filter');
     if (!empty($ipFilter) && !in_array($request->getClientIp(), $ipFilter)) {
         return new JsonResponse(array('success' => false, 'message' => $request->getClientIp() . ' is not allowed'), 400, array('x-enuygun-opcache-clear' => json_encode(array('success' => false, 'message' => $request->getClientIp() . ' is not allowed', 'version' => $version))));
     }
     if (!function_exists('opcache_reset')) {
         throw new \RuntimeException('Opcache extension is not enabled.');
     }
     $success = opcache_reset();
     $message = 'Opcache cleared: ' . ($success ? 'success' : 'failed');
     return new JsonResponse(array('success' => $success, 'message' => $message), 200, array('x-enuygun-opcache-clear' => json_encode(array('success' => $success, 'message' => $message, 'version' => $version))));
 }
开发者ID:EnuygunCom,项目名称:opcache-clear-bundle,代码行数:19,代码来源:OpcacheClearController.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof ReCaptchaConstraint) {
         throw new InvalidArgumentException('Use ReCaptchaConstraint for ReCaptchaValidator.');
     }
     if ($this->request->get('g-recaptcha-response', false)) {
         $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $this->privateKey . "&response=" . $this->request->get('g-recaptcha-response', false) . "&remoteip=" . $this->request->getClientIp()));
         if (!$response->success) {
             $this->context->addViolationAt('recaptcha', $constraint->message);
         }
     } else {
         $this->context->addViolationAt('recaptcha', $constraint->message);
     }
 }
开发者ID:pierre-vassoilles,项目名称:recaptcha-bundle,代码行数:17,代码来源:ReCaptchaValidator.php


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