isRobot() public method

Check if device is a robot.
public isRobot ( string $userAgent = null ) : boolean
$userAgent string
return boolean
Exemplo n.º 1
0
 public function testRobots()
 {
     $agent = new Agent();
     foreach ($this->robots as $robot => $ua) {
         $agent->setUserAgent($ua);
         $this->assertTrue($agent->isRobot());
     }
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 /**
  * 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]);
 }
Exemplo n.º 6
0
 /**
  * Check if device is a robot.
  *
  * @param string $userAgent
  * @return boolean 
  * @static 
  */
 public static function isRobot($userAgent = null)
 {
     return \Jenssegers\Agent\Agent::isRobot($userAgent);
 }