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


PHP Request::getIp方法代码示例

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


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

示例1: enrichVisitWithProviderInfo

 /**
  * Logs the provider in the log_visit table
  */
 public function enrichVisitWithProviderInfo(&$visitorInfo, \Piwik\Tracker\Request $request)
 {
     // if provider info has already been set, abort
     if (!empty($visitorInfo['location_provider'])) {
         return;
     }
     $privacyConfig = new PrivacyManagerConfig();
     $ip = IP::N2P($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp());
     // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking
     if (substr($ip, -2, 2) == '.0') {
         Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup...");
         return;
     }
     $hostname = $this->getHost($ip);
     $hostnameExtension = $this->getCleanHostname($hostname);
     // add the provider value in the table log_visit
     $visitorInfo['location_provider'] = $hostnameExtension;
     $visitorInfo['location_provider'] = substr($visitorInfo['location_provider'], 0, 100);
     // improve the country using the provider extension if valid
     $hostnameDomain = substr($hostnameExtension, 1 + strrpos($hostnameExtension, '.'));
     if ($hostnameDomain == 'uk') {
         $hostnameDomain = 'gb';
     }
     if (array_key_exists($hostnameDomain, Common::getCountriesList())) {
         $visitorInfo['location_country'] = $hostnameDomain;
     }
 }
开发者ID:brienomatty,项目名称:elmsln,代码行数:30,代码来源:Provider.php

示例2: enrichVisitWithLocation

 public function enrichVisitWithLocation(&$visitorInfo, \Piwik\Tracker\Request $request)
 {
     require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php";
     $ipAddress = IP::N2P(Config::getInstance()->Tracker['use_anonymized_ip_for_visit_enrichment'] == 1 ? $visitorInfo['location_ip'] : $request->getIp());
     $userInfo = array('lang' => $visitorInfo['location_browser_lang'], 'ip' => $ipAddress);
     $id = Common::getCurrentLocationProviderId();
     $provider = LocationProvider::getProviderById($id);
     if ($provider === false) {
         $id = DefaultProvider::ID;
         $provider = LocationProvider::getProviderById($id);
         Common::printDebug("GEO: no current location provider sent, falling back to default '{$id}' one.");
     }
     $location = $provider->getLocation($userInfo);
     // if we can't find a location, use default provider
     if ($location === false) {
         $defaultId = DefaultProvider::ID;
         $provider = LocationProvider::getProviderById($defaultId);
         $location = $provider->getLocation($userInfo);
         Common::printDebug("GEO: couldn't find a location with Geo Module '{$id}', using Default '{$defaultId}' provider as fallback...");
         $id = $defaultId;
     }
     Common::printDebug("GEO: Found IP {$ipAddress} location (provider '" . $id . "'): " . var_export($location, true));
     if (empty($location['country_code'])) {
         // sanity check
         $location['country_code'] = \Piwik\Tracker\Visit::UNKNOWN_CODE;
     }
     // add optional location components
     $this->updateVisitInfoWithLocation($visitorInfo, $location);
 }
开发者ID:KiwiJuicer,项目名称:handball-dachau,代码行数:29,代码来源:UserCountry.php

示例3: onNewVisit

 /**
  * @param Request $request
  * @param Visitor $visitor
  * @param Action|null $action
  * @return mixed
  */
 public function onNewVisit(Request $request, Visitor $visitor, $action)
 {
     // Adding &dp=1 will disable the provider plugin, this is an "unofficial" parameter used to speed up log importer
     $disableProvider = $request->getParam('dp');
     if (!empty($disableProvider)) {
         return false;
     }
     // if provider info has already been set, abort
     $locationValue = $visitor->getVisitorColumn('location_provider');
     if (!empty($locationValue)) {
         return false;
     }
     $ip = $visitor->getVisitorColumn('location_ip');
     $privacyConfig = new PrivacyManagerConfig();
     if (!$privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $request->getIp();
     }
     $ip = IPUtils::binaryToStringIP($ip);
     // In case the IP was anonymized, we should not continue since the DNS reverse lookup will fail and this will slow down tracking
     if (substr($ip, -2, 2) == '.0') {
         Common::printDebug("IP Was anonymized so we skip the Provider DNS reverse lookup...");
         return false;
     }
     $hostname = $this->getHost($ip);
     $hostnameExtension = ProviderPlugin::getCleanHostname($hostname);
     // add the provider value in the table log_visit
     $locationProvider = substr($hostnameExtension, 0, 100);
     return $locationProvider;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:35,代码来源:Provider.php

示例4: __construct

 /**
  * @param Request $request
  */
 public function __construct(Request $request)
 {
     $this->spamFilter = new ReferrerSpamFilter();
     $this->request = $request;
     $this->idSite = $request->getIdSite();
     $userAgent = $request->getUserAgent();
     $this->userAgent = Common::unsanitizeInputValue($userAgent);
     $this->ip = $request->getIp();
 }
开发者ID:piwik,项目名称:piwik,代码行数:12,代码来源:VisitExcluded.php

示例5: getIpAddress

 private function getIpAddress($anonymizedIp, \Piwik\Tracker\Request $request)
 {
     $privacyConfig = new PrivacyManagerConfig();
     $ip = $request->getIp();
     if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $anonymizedIp;
     }
     $ipAddress = IP::N2P($ip);
     return $ipAddress;
 }
开发者ID:josl,项目名称:CGE-File-Sharing,代码行数:10,代码来源:Base.php

示例6: __construct

 /**
  * @param Request $request
  * @param bool|string $ip
  * @param bool|string $userAgent
  */
 public function __construct(Request $request, $ip = false, $userAgent = false)
 {
     if ($ip === false) {
         $ip = $request->getIp();
     }
     if ($userAgent === false) {
         $userAgent = $request->getUserAgent();
     }
     $this->request = $request;
     $this->idSite = $request->getIdSite();
     $this->userAgent = $userAgent;
     $this->ip = $ip;
 }
开发者ID:KiwiJuicer,项目名称:handball-dachau,代码行数:18,代码来源:VisitExcluded.php

示例7: __construct

 /**
  * @param Request $request
  * @param bool|string $ip
  * @param bool|string $userAgent
  */
 public function __construct(Request $request, $ip = false, $userAgent = false)
 {
     $this->spamFilter = new ReferrerSpamFilter();
     if (false === $ip) {
         $ip = $request->getIp();
     }
     if (false === $userAgent) {
         $userAgent = $request->getUserAgent();
     }
     $this->request = $request;
     $this->idSite = $request->getIdSite();
     $this->userAgent = $userAgent;
     $this->ip = $ip;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:19,代码来源:VisitExcluded.php

示例8: getIpAddress

 /**
  *
  * @param Visitor $visitor            
  * @param Request $request            
  *
  * @return string
  */
 private function getIpAddress(Visitor $visitor, Request $request)
 {
     if ($this->ipToUse !== null) {
         return $this->ipToUse;
     }
     $privacyConfig = new PrivacyManagerConfig();
     $ip = $request->getIp();
     if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $visitor->getVisitorColumn('location_ip');
     }
     $ip = IPUtils::binaryToStringIP($ip);
     $this->ipToUse = $ip;
     return $ip;
 }
开发者ID:ThaDafinser,项目名称:Piwik-GeoIpChain,代码行数:21,代码来源:AbstractVisitDimension.php

示例9: processRequestParams

 public function processRequestParams(VisitProperties $visitProperties, Request $request)
 {
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $visitProperties->setProperty('location_ip', $request->getIp());
     // TODO: move VisitExcluded logic to here (or move to service class stored in DI)
     $excluded = new VisitExcluded($request, $visitProperties->getProperty('location_ip'));
     if ($excluded->isExcluded()) {
         return true;
     }
     // visitor recognition
     $visitorId = $this->userSettings->getConfigId($request, $visitProperties->getProperty('location_ip'));
     $request->setMetadata('CoreHome', 'visitorId', $visitorId);
     $isKnown = $this->visitorRecognizer->findKnownVisitor($visitorId, $visitProperties, $request);
     $request->setMetadata('CoreHome', 'isVisitorKnown', $isKnown);
     $isNewVisit = $this->isVisitNew($visitProperties, $request);
     $request->setMetadata('CoreHome', 'isNewVisit', $isNewVisit);
     return false;
 }
开发者ID:FluentDevelopment,项目名称:piwik,代码行数:18,代码来源:VisitRequestProcessor.php

示例10: insertVisitorLocation

 public function insertVisitorLocation(&$visitorInfo, \Piwik\Tracker\Request $request)
 {
     $dbPath = PIWIK_INCLUDE_PATH . '/plugins/IP2Location/data/';
     $dbFile = '';
     if ($handle = opendir($dbPath)) {
         while (false !== ($file = readdir($handle))) {
             if (strtoupper(substr($file, -4)) == '.BIN') {
                 $dbFile = $dbPath . $file;
                 break;
             }
         }
         closedir($handle);
     }
     if ($dbFile) {
         $privacyConfig = new PrivacyManagerConfig();
         $ipAddress = IPUtils::binaryToStringIP($privacyConfig->useAnonymizedIpForVisitEnrichment ? $visitorInfo['location_ip'] : $request->getIp());
         $result = IP2LocationAPI::lookup($ipAddress, $dbFile);
         $countryCode = $result['countryCode'] != '-' ? strtolower($result['countryCode']) : null;
         $regionName = $result['regionName'] != '-' ? $result['regionName'] : null;
         $regionCode = $this->getRegionCode(strtoupper($countryCode), $regionName);
         $cityName = !preg_match('/not supported/', $result['cityName']) && $result['cityName'] != '-' ? $result['cityName'] : null;
         $latitude = !preg_match('/not supported/', $result['latitude']) && $result['latitude'] != '-' ? $result['latitude'] : null;
         $longitude = !preg_match('/not supported/', $result['longitude']) && $result['longitude'] != '-' ? $result['longitude'] : null;
         if ($countryCode) {
             $visitorInfo['location_country'] = $countryCode;
         }
         if ($regionCode) {
             $visitorInfo['location_region'] = $regionCode;
         }
         if ($cityName) {
             $visitorInfo['location_city'] = $cityName;
         }
         if ($latitude) {
             $visitorInfo['location_latitude'] = $latitude;
         }
         if ($longitude) {
             $visitorInfo['location_longitude'] = $longitude;
         }
     }
 }
开发者ID:bossrabbit,项目名称:piwik,代码行数:40,代码来源:IP2Location.php

示例11: processRequestParams

 public function processRequestParams(VisitProperties $visitProperties, Request $request)
 {
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $visitProperties->setProperty('location_ip', $request->getIp());
     $excluded = new VisitExcluded($request);
     if ($excluded->isExcluded()) {
         return true;
     }
     $privacyConfig = new PrivacyManagerConfig();
     $ip = $request->getIpString();
     if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
         $ip = $visitProperties->getProperty('location_ip');
     }
     // visitor recognition
     $visitorId = $this->userSettings->getConfigId($request, $ip);
     $request->setMetadata('CoreHome', 'visitorId', $visitorId);
     $isKnown = $this->visitorRecognizer->findKnownVisitor($visitorId, $visitProperties, $request);
     $request->setMetadata('CoreHome', 'isVisitorKnown', $isKnown);
     $isNewVisit = $this->isVisitNew($visitProperties, $request);
     $request->setMetadata('CoreHome', 'isNewVisit', $isNewVisit);
     return false;
 }
开发者ID:piwik,项目名称:piwik,代码行数:22,代码来源:VisitRequestProcessor.php

示例12: handle

 /**
  *    Main algorithm to handle the visit.
  *
  *  Once we have the visitor information, we have to determine if the visit is a new or a known visit.
  *
  * 1) When the last action was done more than 30min ago,
  *      or if the visitor is new, then this is a new visit.
  *
  * 2) If the last action is less than 30min ago, then the same visit is going on.
  *    Because the visit goes on, we can get the time spent during the last action.
  *
  * NB:
  *  - In the case of a new visit, then the time spent
  *    during the last action of the previous visit is unknown.
  *
  *    - In the case of a new visit but with a known visitor,
  *    we can set the 'returning visitor' flag.
  *
  * In all the cases we set a cookie to the visitor with the new information.
  */
 public function handle()
 {
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $this->visitorInfo['location_ip'] = $this->request->getIp();
     $excluded = new VisitExcluded($this->request, $this->visitorInfo['location_ip']);
     if ($excluded->isExcluded()) {
         return;
     }
     /**
      * Triggered after visits are tested for exclusion so plugins can modify the IP address
      * persisted with a visit.
      *
      * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses.
      *
      * @param string &$ip The visitor's IP address.
      */
     Piwik::postEvent('Tracker.setVisitorIp', array(&$this->visitorInfo['location_ip']));
     $this->visitorCustomVariables = $this->request->getCustomVariables($scope = 'visit');
     if (!empty($this->visitorCustomVariables)) {
         Common::printDebug("Visit level Custom Variables: ");
         Common::printDebug($this->visitorCustomVariables);
     }
     $this->goalManager = new GoalManager($this->request);
     $visitIsConverted = false;
     $action = null;
     $isManualGoalConversion = $this->goalManager->isManualGoalConversion();
     $requestIsEcommerce = $this->goalManager->requestIsEcommerce;
     if ($requestIsEcommerce) {
         $someGoalsConverted = true;
         // Mark the visit as Converted only if it is an order (not for a Cart update)
         if ($this->goalManager->isGoalAnOrder()) {
             $visitIsConverted = true;
         }
     } elseif ($isManualGoalConversion) {
         // this request is from the JS call to piwikTracker.trackGoal()
         $someGoalsConverted = $this->goalManager->detectGoalId($this->request->getIdSite());
         $visitIsConverted = $someGoalsConverted;
         // if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request
         if (!$someGoalsConverted) {
             Common::printDebug('Invalid goal tracking request for goal id = ' . $this->goalManager->idGoal);
             return;
         }
     } else {
         // normal page view, potentially triggering a URL matching goal
         $action = Action::factory($this->request);
         $action->writeDebugInfo();
         $someGoalsConverted = $this->goalManager->detectGoalsMatchingUrl($this->request->getIdSite(), $action);
         $visitIsConverted = $someGoalsConverted;
         $action->loadIdsFromLogActionTable();
     }
     /***
      * Visitor recognition
      */
     $visitorId = $this->getSettingsObject()->getConfigId();
     $visitor = new Visitor($this->request, $visitorId, $this->visitorInfo, $this->visitorCustomVariables);
     $visitor->recognize();
     $this->visitorInfo = $visitor->getVisitorInfo();
     $isLastActionInTheSameVisit = $this->isLastActionInTheSameVisit($visitor);
     if (!$isLastActionInTheSameVisit) {
         Common::printDebug("Visitor detected, but last action was more than 30 minutes ago...");
     }
     // Known visit when:
     // ( - the visitor has the Piwik cookie with the idcookie ID used by Piwik to match the visitor
     //   OR
     //   - the visitor doesn't have the Piwik cookie but could be match using heuristics @see recognizeTheVisitor()
     // )
     // AND
     // - the last page view for this visitor was less than 30 minutes ago @see isLastActionInTheSameVisit()
     if ($visitor->isVisitorKnown() && $isLastActionInTheSameVisit) {
         $idReferrerActionUrl = $this->visitorInfo['visit_exit_idaction_url'];
         $idReferrerActionName = $this->visitorInfo['visit_exit_idaction_name'];
         try {
             $this->goalManager->detectIsThereExistingCartInVisit($this->visitorInfo);
             $this->handleExistingVisit($visitor, $action, $visitIsConverted);
             if (!is_null($action)) {
                 $action->record($visitor, $idReferrerActionUrl, $idReferrerActionName);
             }
         } catch (VisitorNotFoundInDb $e) {
             // There is an edge case when:
             // - two manual goal conversions happen in the same second
//.........这里部分代码省略.........
开发者ID:TensorWrenchOSS,项目名称:piwik,代码行数:101,代码来源:Visit.php

示例13: popout

 public function popout()
 {
     header("Access-Control-Allow-Origin: *");
     $params = UrlHelper::getArrayFromQueryString($_SERVER['QUERY_STRING']);
     $request = new Tracker\Request($params);
     // the IP is needed by isExcluded() and GoalManager->recordGoals()
     $ip = $request->getIp();
     $visitorInfo['location_ip'] = $ip;
     /**
      * Triggered after visits are tested for exclusion so plugins can modify the IP address
      * persisted with a visit.
      *
      * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses.
      *
      * @param string &$ip The visitor's IP address.
      */
     Piwik::postEvent('Tracker.setVisitorIp', array(&$visitorInfo['location_ip']));
     /***
      * Visitor recognition
      */
     $settings = new Tracker\Settings($request, $visitorInfo['location_ip']);
     $visitor = new Visitor($request, $settings->getConfigId(), $visitorInfo);
     $visitor->recognize();
     $visitorInfo = $visitor->getVisitorInfo();
     if (!isset($visitorInfo['location_browser_lang'])) {
         return "Who are you ?";
     }
     $idSite = Common::getRequestVar('idsite', null, 'int');
     $conversation = new ChatConversation($idSite, bin2hex($visitorInfo['idvisitor']));
     /***
      * Segment recognition
      */
     foreach (ChatAutomaticMessage::getAll($idSite) as $autoMsg) {
         $segment = ChatSegment::get($autoMsg['segmentID']);
         $fetchSegment = new Segment($segment['definition'], array($idSite));
         $query = $fetchSegment->getSelectQuery("idvisitor", "log_visit", "log_visit.idvisitor = ?", array($visitorInfo['idvisitor']));
         $rows = Db::fetchAll($query['sql'], $query['bind']);
         if (count($rows) == 0) {
             continue;
         }
         if ($autoMsg['segmentID'] != $segment['idsegment']) {
             continue;
         }
         $getAlreadyReceivedMsg = $conversation->getAutomaticMessageReceivedById($autoMsg['id']);
         if (count($getAlreadyReceivedMsg) > 0) {
             // If the AutoMsg is a "one shot"
             if ($autoMsg['frequency'] == 0) {
                 continue;
             }
             if ($autoMsg['frequency'] != 0) {
                 // Now, we gonna try to define when the last AutoMsg received has been sent
                 list($freqTime, $freqScale) = explode('|', $autoMsg['frequency']);
                 if ($freqScale == "w") {
                     $dayMultiplier = 7;
                 } elseif ($freqScale == "m") {
                     $dayMultiplier = 30;
                 } else {
                     $dayMultiplier = 1;
                 }
                 $secToWait = 3600 * 24 * $freqTime * $dayMultiplier;
                 // Is it older than the time range needed to wait ?
                 if ($getAlreadyReceivedMsg[0]['microtime'] + $secToWait > microtime(true)) {
                     continue;
                 }
             }
         }
         $conversation->sendMessage($autoMsg['message'], $autoMsg['transmitter'], $autoMsg['id']);
     }
     $view = new View('@Chat/popout.twig');
     $view->idvisitor = bin2hex($visitorInfo['idvisitor']);
     $view->idsite = $idSite;
     $view->timeLimit = time() - 2 * 60 * 60;
     $view->isStaffOnline = ChatPiwikUser::isStaffOnline();
     $view->siteUrl = ChatSite::getMainUrl($idSite);
     $view->lang = $visitorInfo['location_browser_lang'];
     return $view->render();
 }
开发者ID:WHATNEXTLIMITED,项目名称:piwik-chat,代码行数:77,代码来源:Controller.php


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