Class Methods β
On this page, you will learn about all the methods currently available within the package. You may be interested in adding new features, so we invite you to contribute to this useful solution.
Get β
This method returns the complete user connection agent based on the information gathered from the PHP global variable $_SERVER.
use Rmunate\AgentDetection\Agent;
Agent::get();
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ... Safari/537.36"
use Rmunate\AgentDetection\Agent;
Agent::get();
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ... Safari/537.36"
Set β
At times, you may need the package to analyze an agent different from the one identified by the server. In such cases, you can use the set
method, passing a string
with the agent value:
use Rmunate\AgentDetection\Agent;
Agent::set("Mozilla/5.0...")->isMobile();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::set("Mozilla/5.0...")->isMobile();
// True Or False
After the set
method, you can chain any of the methods available in this guide.
Detected β
This method instructs the class to take the value identified by the server and then chain any other method from this guide.
use Rmunate\AgentDetection\Agent;
Agent::detected()->isMobile();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::detected()->isMobile();
// True Or False
Since version 1.4.0, its use is not mandatory; now you can pass the final method directly to the class for querying.
Is Mobile Connection β
This method validates if the connection is from a mobile device (tablet, smartphone, etc.). You can use it directly on the Agent class.
use Rmunate\AgentDetection\Agent;
Agent::isMobile();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isMobile();
// True Or False
Is Desktop Connection β
This method validates if the connection is from a desktop device. You can use it directly on the Agent class.
use Rmunate\AgentDetection\Agent;
Agent::isDesktop();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isDesktop();
// True Or False
From iPhone β
This method validates if the connection is from an iPhone specifically, not validating iPad or similar devices; it is limited to checking if the connecting device is an iPhone.
use Rmunate\AgentDetection\Agent;
Agent::isIPhone();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isIPhone();
// True Or False
From Macintosh β
This method validates if the connection is from a Macintosh device specifically, not validating iMac or similar devices.
use Rmunate\AgentDetection\Agent;
Agent::isMacintosh();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isMacintosh();
// True Or False
From iMac β
This method validates if the connection is from an iMac specifically, not validating Macintosh or similar devices.
use Rmunate\AgentDetection\Agent;
Agent::isIMac();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isIMac();
// True Or False
From iPod β
This method validates if the connection is from an iPod specifically, not validating similar devices.
use Rmunate\AgentDetection\Agent;
Agent::isIpod();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isIpod();
// True Or False
From iPad β
This method validates if the connection is from an iPad specifically, not validating similar devices.
use Rmunate\AgentDetection\Agent;
Agent::isIpad();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isIpad();
// True Or False
From Linux β
This method validates if the connection is from a device with the Linux operating system (regardless of the distribution).
use Rmunate\AgentDetection\Agent;
Agent::isLinux();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isLinux();
// True Or False
From Android β
This method validates if the connection is from a device with the Android operating system, commonly working on Linux but determining if an Android is in use.
use Rmunate\AgentDetection\Agent;
Agent::isAndroid();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isAndroid();
// True Or False
From Windows β
This method validates if the connection is from a device with the Windows operating system, specifically Windows Desktop.
use Rmunate\AgentDetection\Agent;
Agent::isWindows();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isWindows();
// True Or False
From Windows Phone β
Although rare, if there are still users with this technology, we can identify them.
use Rmunate\AgentDetection\Agent;
Agent::isWindowsPhone();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isWindowsPhone();
// True Or False
From a Tablet β
Sometimes we need to adjust content for tablets, so with this method, you can determine if the connection is from a tablet.
use Rmunate\AgentDetection\Agent;
Agent::isTablet();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isTablet();
// True Or False
Is Crawler β
If we need to validate if the agent is a crawler, we can do so extremely simply:
use Rmunate\AgentDetection\Agent;
Agent::isCrawler();
// True Or False
Agent::set('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')->isCrawler();
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::isCrawler();
// True Or False
Agent::set('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')->isCrawler();
// True Or False
Get Crawler β
If, more than validating if it is a crawler, you need to extract it from the agent, you can use the following method:
use Rmunate\AgentDetection\Agent;
Agent::set('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')->getCrawler();
// "Sosospider"
use Rmunate\AgentDetection\Agent;
Agent::set('Mozilla/5.0 (compatible; Sosospider/2.0; +http://help.soso.com/webspider.htm)')->getCrawler();
// "Sosospider"
Validate by Match β
If you want to have a dynamic method of validating the agent, you may find it convenient to use the following method supplied by the package:
use Rmunate\AgentDetection\Agent;
Agent::match('Mac');
// True Or False
use Rmunate\AgentDetection\Agent;
Agent::match('Mac');
// True Or False
Get Operating System β
If you want to extract the value of the operating system in use from the agent, it will be more convenient to use the following method.
use Rmunate\AgentDetection\Agent;
Agent::clientOS();
// 'Windows' // 'Mac' // 'Linux' // 'Android' // 'iOS'
use Rmunate\AgentDetection\Agent;
Agent::clientOS();
// 'Windows' // 'Mac' // 'Linux' // 'Android' // 'iOS'
Connection IP β
You can also find out through which IP the Agent connected to the application:
use Rmunate\AgentDetection\Agent;
Agent::remoteAddress();
use Rmunate\AgentDetection\Agent;
Agent::remoteAddress();
Connection Port β
It may be useful to know through which port the connection occurred, so here it is:
use Rmunate\AgentDetection\Agent;
Agent::remotePort();
use Rmunate\AgentDetection\Agent;
Agent::remotePort();
Browser β
Finally, we might be interested in the browser used to access our applications, so with the following method, you can extract all the connection browser data from the agent:
use Rmunate\AgentDetection\Agent;
$browser = Agent::browser();
$browserName = $browser->getName();
$browserVersion = $browser->getVersion();
$browserPlatform = $browser->getPlatform();
use Rmunate\AgentDetection\Agent;
$browser = Agent::browser();
$browserName = $browser->getName();
$browserVersion = $browser->getVersion();
$browserPlatform = $browser->getPlatform();