Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ad-aures/user-agents-php
PHP implementation for opawg/user-agents
https://github.com/ad-aures/user-agents-php
Last synced: about 2 months ago
JSON representation
PHP implementation for opawg/user-agents
- Host: GitHub
- URL: https://github.com/ad-aures/user-agents-php
- Owner: ad-aures
- License: mit
- Created: 2020-10-05T12:43:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-10-05T16:58:32.000Z (over 4 years ago)
- Last Synced: 2024-05-21T01:36:58.938Z (8 months ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 2
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# user-agents-php
This is a dummy PHP implementation for [opawg / user-agents](https://github.com/opawg/user-agents)## Installation
### Via composer
- Add `podlibre/user-agents-php` to your `composer.json`.
- Add `post-install-cmd` / `post-update-cmd` scripts to your `composer.json` so that the class is generated.```
{
"require": {
"podlibre/user-agents-php": "*"
},
"scripts": {
"post-install-cmd": "@php vendor/podlibre/user-agents-php/src/UserAgentsGenerate.php > vendor/podlibre/user-agents-php/src/UserAgents.php",
"post-update-cmd": "@php vendor/podlibre/user-agents-php/src/UserAgentsGenerate.php > vendor/podlibre/user-agents-php/src/UserAgents.php"
}
}
```### Manually
- Clone git repository where you need it:```
$ git clone https://github.com/podlibre/user-agents-php.git
```- Generate the class:
```
$ php src/UserAgentsGenerate.php > src/UserAgents.php
```Or with composer:
```
$ composer run-script post-install-cmd
```## Usage
When you need it, just call `\Podlibre\UserAgentsPhp\UserAgents::find()`:```
$player = \Podlibre\UserAgentsPhp\UserAgents::find($_SERVER['HTTP_USER_AGENT']);
if($player){
print player['app']."\n";
print player['device']."\n";
print player['os']."\n";
print player['bot']."\n";
} else {
print "This user-agent was not found.\n";
}
```