本文整理汇总了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);
}
示例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);
}
示例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']));
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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');
}
示例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');
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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))));
}
示例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);
}
}