示例#1
0
 /**
  * @return array
  */
 public function locate()
 {
     //
     $ip = $this->ip->get();
     $db = $this->config->get('visitor.maxmind_db_path');
     if (!is_string($db) || !file_exists($db) || !$this->ip->isValid($ip)) {
         return [];
     }
     $this->reader = new Reader($db);
     try {
         $record = $this->reader->city($ip);
         return ['country_code' => $record->country->isoCode, 'country_name' => $record->country->name, 'state_code' => $record->mostSpecificSubdivision->isoCode, 'state' => $record->mostSpecificSubdivision->name, 'city' => $record->city->name, 'postale_code' => $record->postal->code];
     } catch (AddressNotFoundException $e) {
         return [];
     }
 }
示例#2
0
 /**
  *
  */
 public function log()
 {
     $ip = $this->ip->get();
     if (!$this->ip->isValid($ip)) {
         return;
     }
     if ($this->has($ip)) {
         //ip already exist in db.
         $this->storage->increment($ip);
     } else {
         $geo = $this->geo->locate($ip);
         $country = array_key_exists('country_code', $geo) ? $geo['country_code'] : null;
         //ip doesnt exist  in db
         $data = array('ip' => $ip, 'country' => $country, 'clicks' => 1, 'updated_at' => c::now(), 'created_at' => c::now());
         $this->storage->create($data);
     }
     // Clear the database cache
     $this->cache->destroy('weboap.visitor');
 }