File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Binafy \LaravelUserMonitoring \Utills ;
4+
5+ class Detector
6+ {
7+ /**
8+ * Get browser list names.
9+ *
10+ * @var array
11+ */
12+ public array $ browserName = [
13+ 'Edge ' => 'Edge ' ,
14+ 'MSIE ' => 'Internet Explorer ' ,
15+ 'Trident ' => 'Internet Explorer ' ,
16+ 'Firefox ' => 'Firefox ' ,
17+ 'OPR ' => 'Opera ' ,
18+ 'Chrome ' => 'Chrome ' ,
19+ 'Safari ' => 'Safari ' ,
20+ 'Opera ' => 'Opera ' ,
21+ ];
22+
23+ /**
24+ * Get device list names.
25+ *
26+ * @var array
27+ */
28+ public array $ deviceName = [
29+ '/iPhone/i ' => 'iPhone ' ,
30+ '/iPad/i ' => 'iPad ' ,
31+ '/Android/i ' => 'Android Device ' ,
32+ '/Windows/i ' => 'Windows ' ,
33+ ];
34+
35+ /**
36+ * Get browser name.
37+ */
38+ public function getBrowser (): string
39+ {
40+ $ userAgent = $ _SERVER ['HTTP_USER_AGENT ' ];
41+
42+ foreach ($ this ->browserName as $ key => $ browser ) {
43+ if (str_contains ($ userAgent , $ key )) {
44+ return $ browser ;
45+ }
46+ }
47+
48+ return 'Unknown Browser ' ;
49+ }
50+
51+ /**
52+ * Get device name.
53+ */
54+ public function getDevice (): string
55+ {
56+ $ userAgent = $ _SERVER ['HTTP_USER_AGENT ' ];
57+
58+ foreach ($ this ->deviceName as $ pattern => $ name ) {
59+ if (preg_match ($ pattern , $ userAgent )) {
60+ return $ name ;
61+ }
62+ }
63+
64+ return 'Unknown Device Name ' ;
65+ }
66+ }
You can’t perform that action at this time.
0 commit comments