yandex / detector
用于与 Yandex.Detector 交互的 PHP 库 / PHP 实现了与雅虎.检测器服务交互的 API
v1.1.0
2015-01-23 19:56 UTC
Requires
- php: >=5.3.0
- lib-curl: *
This package is not auto-updated.
Last update: 2024-09-24 01:28:04 UTC
README
雅虎.检测器 API 提供了根据浏览器发送的 HTTP 请求标题,识别用户网站移动设备模型和特性的功能。
示例
<?php $api = new \Yandex\Detector\Api(); try { // Взять параметры из заголовков, переданных серверу $api->load(); // Или указать параметры вручную $api ->reset() ->setUserAgent('Alcatel-CTH3/1.0 UP.Browser/6.2.ALCATEL MMP/1.0') ->setWapProfile('http://www-ccpp-mpd.alcatel.com/files/ALCATEL-CTH3_MMS10_1.0.rdf') ->load(); } catch (\Yandex\Detector\Exception $ex) { } $response = $api->getResponse(); if (!$response) { echo 'Телефон не определен'; } else { echo $response->getName(); echo $response->getVendor(); if ($response->isIphone()) { } elseif ($response->isAndroid()) { } echo $response->getScreenWidth() . 'x' . $response->getScreenHeight(); }
还可以覆盖 curl 发送请求的参数(例如,为了增加连接等待时间)。
<?php $api = new \Yandex\Detector\Api(array(CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_TIMEOUT => 30)); // ...