Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Dylan Lopez
Added: Mar 6, 2018 8:52 AM
Views: 5
  1. //When the User Agent class is initialized it will attempt to determine whether the user agent browsing your site is a web browser, a mobile device, or a robot. It will also gather the platform information if it is available.
  2. $this->load->library('user_agent');
  3.  
  4. if ($this->agent->is_browser())
  5. {
  6.         $agent = $this->agent->browser().' '.$this->agent->version();
  7. }
  8. elseif ($this->agent->is_robot())
  9. {
  10.         $agent = $this->agent->robot();
  11. }
  12. elseif ($this->agent->is_mobile())
  13. {
  14.         $agent = $this->agent->mobile();
  15. }
  16. else
  17. {
  18.         $agent = 'Unidentified User Agent';
  19. }
  20.  
  21. echo $agent;
  22.  
  23. echo $this->agent->platform(); // Platform info (Windows, Linux, Mac, etc.)