Created
November 11, 2025 08:14
-
-
Save szepeviktor/09e69861987226e8337d77b0f5d5e561 to your computer and use it in GitHub Desktop.
Detect HTTP requests from humans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| #$ composer require matomo/device-detector | |
| require __DIR__.'/vendor/autoload.php'; | |
| use DeviceDetector\DeviceDetector; | |
| use DeviceDetector\Parser\Device\AbstractDeviceParser; | |
| AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE); | |
| while (!feof(STDIN)) { | |
| $ua = trim(fgets(STDIN)); | |
| if ($ua === '') continue; | |
| $dd = new DeviceDetector($ua); | |
| $dd->parse(); | |
| $isHuman = !$dd->isBot() | |
| && ($dd->getDeviceName() === 'desktop' || $dd->isSmartphone() || $dd->isFeaturePhone() || $dd->isTablet() || $dd->isPhablet()) | |
| && ($dd->isBrowser() || $dd->isMobileApp()); | |
| if ($isHuman) { | |
| echo $ua, PHP_EOL; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
cut -d'"' -f6 access.log | php is-human.php