Coder Social home page Coder Social logo

Browser->Name Not working about parser-php HOT 2 CLOSED

AustenZeh avatar AustenZeh commented on June 14, 2024
Browser->Name Not working

from parser-php.

Comments (2)

matinaspatsos avatar matinaspatsos commented on June 14, 2024

Undefined property: stdClass::$name means that you have an undefined object. If I remember correctly, I think the reason why is because it is expecting a single agent string string instead of an array. I think you will have to loop through, and do $user = new WhichBrowser($agents); with each agent string.

To start to debug, walkthrough and var_dump everything. So do something like this: Try this:

$user = new WhichBrowser($agents);
var_dump($user);

// If it produces errors here, that probably means that $agents is not the data type that the WhichBrowser object is expecting.
$user = new WhichBrowser($agents);
var_dump($user);

$browser = $user->browser->name;
var_dump($browser);

Try that and see where you get the error.


From: AustenZeh [email protected]
Sent: Wednesday, July 15, 2015 3:12 PM
To: WhichBrowser/WhichBrowser
Subject: [WhichBrowser] Browser->Name Not working (#38)

Every time I write code like so:

$user = new WhichBrowser($agents);
$user->analyseUserAgent($agents['ua']);
$browser = $user->browser->name;

where agents is an array of Agent Strings, I get an error that reads:

Notice: Undefined property: stdClass::$name in.....

and I was hoping someone could help me out, because it does the same thing for when I try to get the version of the browser or the OS. Really the only thing that works is when I analyse the device so please help, thank you!

Reply to this email directly or view it on GitHubhttps://github.com//issues/38.

from parser-php.

NielsLeenheer avatar NielsLeenheer commented on June 14, 2024

Using WhichBrowser from PHP isn't officially supported yet, but if you do want to use it, you need pass an options array with the headers to the WhichBrowser object. Also keep in mind that name is not always defined. Only when WhichBrowser knows the name it will set this property.

$options = array('headers' => getallheaders());
$user = new WhichBrowser($options);

if (isset($user->browser->name)) {
   echo $user->browser->name;
} else {
   echo "Browser name is not known";
}

If you just have a user agent string you want to analyse you need to do it like this:

$options = array('headers' => array('User-Agent' => 'Mozilla/5.0........'));
$user = new WhichBrowser($options);

if (isset($user->browser->name)) {
   echo $user->browser->name;
} else {
   echo "Browser name is not known";
}

from parser-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.