Filter Useagent Via Database

Asked

Viewed 51 times

0

I created a table that receives some visitor information, ID, Useagent, Address and proxy.

I am making a chart type those pie (Chart pie) and would like to show the amount of visits of Y browsers and X of others.

Ex: the 3 most last browsers and the fourth number would be "other".

I thought of several methods to do this, since there is a field called Useagent that receives $_SERVER['HTTP_USER_AGENT'] I thought to search with WHERE LIKE, but for this I need to make a list of strings, there is another easier way, without modifying the DB ?

2 answers

1

Amid the many researches I did when actively programming, I came to elaborate this class to obtain various information about the user’s browser.

The use, assuming the class has been included, is simple:

$browser = new Browser;

print '<pre>'; print_r( $browser -> getInfo() );

And the return:

Browser Object
(
    [agent] => Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
    [browser] => Chrome
    [version] => 36.0.1985.125
    [platform] => Windows
    [isMobile] => 
    [isRobot] => 
    [IP] => 
)

That way you don’t need to store the user-agent, then consult it and analyze your information to store again, query this analyzed data and only then assemble the chart.

There are some considerations to be made:

  • This component was part of something bigger and therefore there are dependencies. However, it is perfectly possible to remove such dependencies simply by removing the namespace (and the use below) and change extends Objectfor extends stdClass.

  • In the output above we have some empty entries.

    • isMobile When the Request originated from a device mobile this entry is set as TRUE.

    • isRobot When the Requisition was made by a webcrawler (Googlebot and cia. ) this entry is set as TRUE.

    It’s not that they’re not working, it turns out I’m using a print_r() and, for him, FALSE, which are the values of the entries at that time, do not appear.

  • Still in the output we have the entry referring to the user’s IP. Also to the above mentioned problem, print_r() does not show NULL.

    And this entry is only not appearing because the routine that detects the user’s IP, is supported in getenv() and I am currently running on CLI, where environment information should be set manually.

  • 1

    May I disagree with the timing of his execution? Statistics are tracking information should not interfere with the system, so I don’t think they should be processed immediately.

  • It really is a valid point, but let’s come and agree that not every site is like Google right? I don’t know when the statistics of a particular Analytics report are actually computed, whether daily or weekly, but for us mortals, this is not always how the band plays and it is even feasible to anticipate this data uncle.

  • No doubt for small sites may not matter much. I believe monitoring sites work this way, even by delay, partly by the analysis tools as a whole. I see statistics as human analysis, webcrawler would not compute visited pages and fraud should be observed, so there will be more rules and exceptions that will be processed - so I set the moment to produce them. Your class could work with a Request separate, ai could use the two classes together

  • If you look in this repository you will see that two levels above have a separate Request class, hehe.

  • Had not seen :) This makes the class good to serve as a LIB. I’ll take a consultation calmly

1

If I were to log statistics, I would use a temporary TBL to store raw information - ID, Useagent, Address, Referrer... each in a field

Basiclog:
ID | UseAgent | Referrer

It’s pretty raw data and you don’t need it on-time.
The next step would be to convert into statistics. I would create a TBL with the other information that can be obtained( browser, version, OS, IP, referrer, date-time...)

Stats:
browser | version | OS | IP | referrer | time | page


Basically you will run a script to get the information in Basiclog, extract the information, save in Stats and can clear the Basiclog.
So you can have all the individualized information ready to generate a graph with all the information of the accesses, most accessed pages...

  • I was doing it the way you mentioned, but my class wasn’t that good, so I created a new one that now stores Useagent.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.