You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Helps detect the user's browser and platform at the PHP level via the user agent
6
6
7
7
8
8
## Installation
9
9
10
-
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
10
+
### Via Composer (Recommended)
11
11
12
-
composer require cbschuld/browser.php
12
+
```bash
13
+
composer require cbschuld/browser.php
14
+
```
15
+
16
+
For development only:
17
+
```bash
18
+
composer require --dev cbschuld/browser.php
19
+
```
20
+
21
+
### Direct Download
22
+
23
+
Download `Browser.php` and include it in your project:
24
+
```php
25
+
require_once 'Browser.php';
26
+
```
13
27
14
-
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
28
+
## Usage
15
29
16
-
composer require --dev cbschuld/browser.php
30
+
### Modern Usage (v2.0+, Recommended)
31
+
32
+
```php
33
+
use cbschuld\Browser;
17
34
35
+
$browser = new Browser();
36
+
if ($browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->compareVersion('10', '>=')) {
37
+
echo 'You have Firefox version 10 or greater';
38
+
}
39
+
```
18
40
19
-
##Typical Usage:
41
+
### Legacy Usage (Still Supported)
20
42
21
43
```php
44
+
// Works via automatic aliasing - no namespace needed
@@ -87,7 +129,7 @@ Detecting the user's browser type and version is helpful in web applications tha
87
129
88
130
In an active project of mine we have a pretty graphically intensive and visually appealing user interface which leverages a lot of transparent PNG files. Because we all know how great IE6 supports PNG files it was necessary for us to tell our users the lack of power their browser has in a kind way.
89
131
90
-
Searching for a way to do this at the PHP layer and not at the client layer was more of a challenge than I would have guessed; the only script available was written by Gary White and Gary no longer maintains this script because of reliability. I do agree 100% with Gary about the readability; however, there are realistic reasons to desire the user.s browser and browser version and if your visitor is not echoing a false user agent we can take an educated guess.
132
+
Searching for a way to do this at the PHP layer and not at the client layer was more of a challenge than I would have guessed; the only script available was written by Gary White and Gary no longer maintains this script because of reliability. I do agree 100% with Gary about the readability; however, there are realistic reasons to desire the user's browser and browser version and if your visitor is not echoing a false user agent we can take an educated guess.
91
133
92
134
I based this solution off of Gary White's original work but have since replaced all of his original code. Either way, thank you to Gary. Sadly, I never was able to get in touch with him regarding this solution.
93
135
@@ -106,7 +148,17 @@ Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Ge
106
148
Tests can be run by phpunit:
107
149
108
150
```bash
109
-
vendor/phpunit/phpunit/phpunit
151
+
vendor/bin/phpunit
110
152
```
111
153
154
+
## Upgrading from v1.x
155
+
156
+
See [UPGRADING.md](UPGRADING.md) for detailed migration instructions.
157
+
158
+
**Quick Summary:**
159
+
- v2.0 requires PHP 8.0+
160
+
- Class is now namespaced: `cbschuld\Browser`
161
+
- Backward compatibility maintained via automatic aliasing
162
+
- Use `compareVersion()` for reliable version comparisons
0 commit comments