lexinzector/aboutguest
Composer 安装命令:
composer require lexinzector/aboutguest
包简介
User information in PHP - IP, browser, operating system, robot
README 文档
README
User information in PHP - IP, browser, operating system, robot
Provides
- browser name
- browser version
- operating system name
- operating system version/kernel
- visitor IP
- check: whether the user has logged in from a browser
- check: whether the user is logged in from a mobile device
- name of brand/OS/browser of mobile phone, smartphone, tablet
- check: whether the visitor is a search engine robot
- which search engine does the robot belong to
How the PHP class works to determine visitor data by user-agent
From the arrays folder, associative arrays are loaded that contain abbreviations or short names of browsers, operating systems or robots that appear in the user-agent line that we receive from the browser. After receiving the data, all methods that have the set_ prefix are dynamically called and fill the class variables, because only they are public and can be taken out of the scope of the class.
Requirements
PHP >= 5.6.0
Installation
run in console:
composer require lexinzector/aboutguest
Methods
$this->load($file_and_array_name)
Loader. This method loads arrays from the arrays folder and assigns them to the variable specified in the value of the $file_and_array_name attribute, this attribute is also the name of the file from the arrays folder.
$this->set_ip()
Returns a value from the $_SERVER array with the REMOTE_ADDR key, as you know $_SERVER['REMOTE_ADDR'] is the user's IP that is accessible to the browser.
$this->set_browser()
array file: arrays / browsers.php After the $this->load method has loaded the arrays, this method will work with the array from the $this->browsers object. Once it finds a match between the array key and the contents of the string in $this->agent, it assigns the $this->browser object the value of the key in the $this->browsers array. Also, this method also assigns the browser version in $this->version. Since the browser has already found a match, there is no doubt that the user came from the browser and did not access the site through a script. Set $this->is_browser to True;
$this->set_operating_system()
array file: arrays / operating_systems.php It works in the same way as the $this->set_browser method, except that it uses the $this->operating_systems object as an array to check for a match, which received the array from the arrays/operating_systems.php file after executing the $this->load() method. Unfortunately, browsers are not so active in dealing with the version of the operating system and sometimes you can get strange numbers instead of the version. So be careful when you use $this->os_version. The name of the operating system is contained in $this->operating_system (not to be confused with $this->os_version)
$this->set_robot()
array file: arrays / robots.php We check if the site visitor is not a search engine robot. If he is a robot then the value for $this->is_robot will be TRUE; the value $this->robot will contain the name of the search engine that launched the robot on the site (Google Bot, Yandex Bot, Rambler Bot...)
$this->set_mobile()
array file: arrays / mobiles.php It works similarly to the $this->set_operating_system() method, only it assigns the name of the phone brand to the $this->mobile object and the value of $this->is_mobile will be TRUE if logged in from a mobile phone, smartphone or tablet.
Example
use \Lexinzector\AboutGuest\AboutGuest; // useragent autodetection $AboutGuest = new AboutGuest; // custom useragent $useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'; $AboutGuest = new AboutGuest($useragent); echo 'User Agent: ' . $AboutGuest->agent . '<br />'; echo 'IP: ' . $AboutGuest->ip . '<br />'; echo 'Browser: ' . $AboutGuest->browser . '<br />'; echo 'Browser version: ' . $AboutGuest->version . '<br />'; echo 'Operating System: ' . $AboutGuest->operating_system . '<br />'; echo 'OS version: ' . $AboutGuest->os_version . '<br />'; echo 'I am a robot? ' . $AboutGuest->is_robot . '<br />'; echo 'Robot belongs: ' . $AboutGuest->robot . '<br />'; echo 'Logged in from a mobile phone? ' . $AboutGuest->is_mobile . '<br />'; echo 'Mobile phone: ' . $AboutGuest->mobile . '<br />';
lexinzector/aboutguest 适用场景与选型建议
lexinzector/aboutguest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「browser」 「IP」 「useragent」 「operating system」 「robot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lexinzector/aboutguest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lexinzector/aboutguest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lexinzector/aboutguest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
Instrument headless chrome/chromium instances from php5.6
Selenium4 (WebDriver) driver for Mink framework
Useragent sniffing library for PHP
Useragent sniffing library for PHP
The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-17