Filters UseAgent Via Database

0

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

I'm doing a pie chart type and would like to show the amount of visits from Y browsers and X from others.

Ex: the 3 most used 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 I would search with WHERE LIKE, but for that I need to make a list of strings, there is another way easier , without modifying the DB?

    
asked by anonymous 01.08.2014 / 04:23

2 answers

1

If I were to do a statistics LOG, I would use a temporary TBL to store the raw information - ID, UseAgent, Address, Referrer ... each in a field

  

BasicLog:
ID | UseAgent | Referrer

They're pretty rough and you do not need them on-time. The next step would be to convert to statistics. I would create a TBL with the other information that can be obtained (browser, version, OS, IP, referrer, date-time ...)

  

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


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

    
01.08.2014 / 05:35
1

In the midst of the many searches I did when I was actively programming, I came up with this class to obtain various information about the user's browser.

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] => 
)

In this way you do not need to store the user-agent , then consult it and analyze its information to store again, consult this analyzed data and then assemble the graph.

There are some things to consider:

  • This component was part of a larger thing, so there are dependencies. However, it is quite possible to remove such dependencies simply by removing the namespace declaration (and the use below it) and changing extends Object by extends stdClass . >

  • In the output above we have some empty entries.

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

    • isRobot When the request was made by a webcrawler (Googlebot and cia.) This entry is set to TRUE .

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

  • In output we also have the entry referring to the IP of the user. Similarly to the problem mentioned above, print_r () does not show NULL .

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

01.08.2014 / 14:58