public function testRobots() { $agent = new Agent(); foreach ($this->robots as $robot => $ua) { $agent->setUserAgent($ua); $this->assertTrue($agent->isRobot()); } }
public function getUA() { // Initialize UA $agent = new Agent(); $browser = $agent->browser(); // Assemble data $data = ['browser' => $browser, 'browser_version' => $agent->version($browser), 'languages' => array($agent->languages()), 'device' => $agent->device(), 'platform' => $agent->platform(), 'is_mobile' => $agent->isMobile(), 'is_tablet' => $agent->isTablet(), 'is_desktop' => $agent->isDesktop(), 'is_robot' => $agent->isRobot(), 'robot_name' => $agent->robot()]; return $data; }
public function getPlatform() { if ($this->agent->isPhone()) { return 'phone'; } if ($this->agent->isTablet()) { return 'tablet'; } if ($this->agent->isMobile()) { return 'mobile'; } if ($this->agent->isDesktop()) { return 'desktop'; } if ($this->agent->isRobot()) { return 'robot'; } return null; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = ['status' => 'ERROR', 'message' => '', 'data' => []]; $ua_hashed = md5('ua_' . $request->server('HTTP_USER_AGENT')); if (!Cache::has($ua_hashed)) { $agent = new Agent(); $is_bot = $agent->isRobot(); Cache::forever($ua_hashed, $is_bot); } else { $is_bot = Cache::get($ua_hashed); } if ($is_bot) { $response['message'] = 'Bot request is not allowed.'; return response()->json($response, 403); } return $next($request); }
/** * Record the visitation. * * @param Request $request * @author Cali */ public static function visited(Request $request) { $userAgent = new Agent(); $location = Location::get(); static::create(['referer' => url()->previous(), 'uri' => $request->path(), 'browser' => $userAgent->browser(), 'platform' => $userAgent->platform(), 'device' => $userAgent->device(), 'mobile' => !$userAgent->isDesktop(), 'ip' => $location->ip, 'country' => $location->isoCode, 'city' => $location->cityName, 'robot' => $userAgent->isRobot() ? $userAgent->robot() : null, 'user_id' => $request->user() ? $request->user()->id : null]); }
/** * Check if device is a robot. * * @param string $userAgent * @return boolean * @static */ public static function isRobot($userAgent = null) { return \Jenssegers\Agent\Agent::isRobot($userAgent); }