如何在php项目中使用Piwik设备检测器? [英] How to use Piwik device detector in php project?

查看:30
本文介绍了如何在php项目中使用Piwik设备检测器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 php 设备检测器,这是一部分著名的 Piwik 项目,但我不明白如何在我的 php 代码中包含和使用代码?我不想使用作曲家.

I want to use php device detector that is part of famous Piwik project, but i can't understand how to include and use the code in my php code? i don't want to use composer.

我写道:

<?php
include 'DeviceDetector.php';
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\DeviceParserAbstract;

$dd = new DeviceDetector($_SERVER['HTTP_USER_AGENT']);

$dd->parse();

$clientInfo = $dd->getClient();
var_dump($clientInfo);

但它不起作用.我收到此错误:

But it doesn't work. i get this error:

Fatal error:  Uncaught exception 'Exception' with message 'client parser not found' in D:\DeviceDetector.php:214
Stack trace:
#0 D:\DeviceDetector.php(136): DeviceDetector\DeviceDetector->addClientParser('FeedReader')
#1 D:\index.php(67): DeviceDetector\DeviceDetector->__construct('Mozilla/5.0 (Wi...')
#2 {main}
  thrown in D:\DeviceDetector.php on line 214

推荐答案

// I figured it out.  Pretty easy.  Grab a copy of master and make a few mods.

// At the top of DeviceDetector.php and in this order:

namespace DeviceDetector;

require_once (dirname(__FILE__).'/spyc.php');

require_once (dirname(__FILE__).'/Cache/Cache.php');
require_once (dirname(__FILE__).'/Cache/StaticCache.php');

require_once (dirname(__FILE__).'/Parser/ParserAbstract.php');

require_once (dirname(__FILE__).'/Parser/Bot.php');
require_once (dirname(__FILE__).'/Parser/OperatingSystem.php');
require_once (dirname(__FILE__).'/Parser/VendorFragment.php');

require_once (dirname(__FILE__).'/Parser/Client/ClientParserAbstract.php');
require_once (dirname(__FILE__).'/Parser/Device/DeviceParserAbstract.php');

require_once (dirname(__FILE__).'/Parser/Client/Browser/Engine.php');

// Add as the first line of addClientParser():
        require_once (dirname(__FILE__).'/Parser/Client/'.$parser.'.php');

// Add as the first line of addDeviceParser():
        require_once (dirname(__FILE__).'/Parser/Device/'.$parser.'.php');

// You'll also have to grab a copy of spyc.php - google it - easy to find.

// That's it.  Works awesome.  Faster than anything else.

这篇关于如何在php项目中使用Piwik设备检测器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆