matomo-org / device-detector

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
http://devicedetector.net
GNU Lesser General Public License v3.0
2.94k stars 476 forks source link

How can I solve Array to String Conversion #5918

Closed HardSoftMac closed 5 years ago

HardSoftMac commented 5 years ago

Hello developer,

I installed through Composer. Now I'm having trouble echoing the variable out.

I have this on top of my page:

`require_once 'vendor/autoload.php';

use DeviceDetector\DeviceDetector; use DeviceDetector\Parser\Device\DeviceParserAbstract;

//DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE);

$userAgent = $_SERVER['HTTP_USER_AGENT']; // change this to the useragent you want to parse

$dd = new DeviceDetector($userAgent);

$dd->parse();

if ($dd->isBot()) { // handle bots,spiders,crawlers,... $botInfo = $dd->getBot(); } else { $clientInfo = $dd->getClient(); // holds information about browser, feed reader, media player, ... $osInfo = $dd->getOs(); $device = $dd->getDeviceName(); $brand = $dd->getBrandName(); $model = $dd->getModel(); }`

And my inputs:

`

                                                        <input type="text" name="device" id="device" value="<?= $device; ?>" />
                                                        <input type="text" name="brand" id="brand" value="<?= $brand; ?>" />
                                                        <input type="text" name="model" id="model" value="<?= $model; ?>" />`

Please help

NOTE: When I removed: //$clientInfo = $dd->getClient(); // holds information about browser, feed reader, media player, ... //$osInfo = $dd->getOs();

no error but only $device = $dd->getDeviceName(); echoed out. Others blank.

Findus23 commented 5 years ago

Hi, the error message says what the error is. You try to print out $clientInfo as a string, but $clientInfo is not a string, but an array. If you want to view the whole content of the array, try print_r() or var_dump().

HardSoftMac commented 5 years ago

Thank you for the response. I got these: Array ( [type] => browser [name] => Chrome [short_name] => CH [version] => 72.0 [engine] => Blink [engine_version] => ) Array ( [name] => Windows [short_name] => WIN [version] => 10 [platform] => x64 )

What I actually want is to save the these information into database and later output in login history as in http://devicedetector.net/

I need name and version to join together: 'name' => string 'Chrome' 'version' => string '72.0' to form: Chrome 72.0

'name' => string 'Windows' 'version' => string '10' to form: Windows 10

Please help.

Findus23 commented 5 years ago

Hi, this is a general programming question and not a bug in device-detector. Please ask on Stackoverflow or the Matomo forum. Also include more details on your setup as it totally depends on what you are programming

HardSoftMac commented 5 years ago

I'm so sorry. I figured it out. Thank you. If you can delete this entire thread, that will be nice. After all, it's not a bug issue.