1+ <?php
2+ /*
3+ #-----------------------------------------
4+ | b1 web analytics: statistics viewer
5+ | https://beranek1.github.io/webanalytics/
6+ #-----------------------------------------
7+ | made by beranek1
8+ | https://github.com/beranek1
9+ #-----------------------------------------
10+ */
11+
12+ $ country_to_continent = array ("AD " =>"EU " ,"AE " =>"AS " ,"AF " =>"AS " ,"AG " =>"NA " ,"AI " =>"NA " ,"AL " =>"EU " ,"AM " =>"AS " ,"AN " =>"NA " ,"AO " =>"AF " ,"AP " =>"AS " ,"AR " =>"SA " ,"AS " =>"OC " ,"AT " =>"EU " ,"AU " =>"OC " ,"AW " =>"NA " ,"AX " =>"EU " ,"AZ " =>"AS " ,"BA " =>"EU " ,"BB " =>"NA " ,"BD " =>"AS " ,"BE " =>"EU " ,"BF " =>"AF " ,"BG " =>"EU " ,"BH " =>"AS " ,"BI " =>"AF " ,"BJ " =>"AF " ,"BL " =>"NA " ,"BM " =>"NA " ,"BN " =>"AS " ,"BO " =>"SA " ,"BR " =>"SA " ,"BS " =>"NA " ,"BT " =>"AS " ,"BV " =>"AN " ,"BW " =>"AF " ,"BY " =>"EU " ,"BZ " =>"NA " ,"CA " =>"NA " ,"CC " =>"AS " ,"CD " =>"AF " ,"CF " =>"AF " ,"CG " =>"AF " ,"CH " =>"EU " ,"CI " =>"AF " ,"CK " =>"OC " ,"CL " =>"SA " ,"CM " =>"AF " ,"CN " =>"AS " ,"CO " =>"SA " ,"CR,NA " ,"CU " =>"NA " ,"CV " =>"AF " ,"CX " =>"AS " ,"CY " =>"AS " ,"CZ " =>"EU " ,"DE " =>"EU " ,"DJ " =>"AF " ,"DK " =>"EU " ,"DM " =>"NA " ,"DO " =>"NA " ,"DZ " =>"AF " ,"EC " =>"SA " ,"EE " =>"EU " ,"EG " =>"AF " ,"EH " =>"AF " ,"ER " =>"AF " ,"ES " =>"EU " ,"ET " =>"AF " ,"EU " =>"EU " ,"FI " =>"EU " ,"FJ " =>"OC " ,"FK " =>"SA " ,"FM " =>"OC " ,"FO " =>"EU " ,"FR " =>"EU " ,"FX " =>"EU " ,"GA " =>"AF " ,"GB " =>"EU " ,"GD " =>"NA " ,"GE " =>"AS " ,"GF " =>"SA " ,"GG " =>"EU " ,"GH " =>"AF " ,"GI " =>"EU " ,"GL " =>"NA " ,"GM " =>"AF " ,"GN " =>"AF " ,"GP " =>"NA " ,"GQ " =>"AF " ,"GR " =>"EU " ,"GS " =>"AN " ,"GT " =>"NA " ,"GU " =>"OC " ,"GW " =>"AF " ,"GY " =>"SA " ,"HK " =>"AS " ,"HM " =>"AN " ,"HN " =>"NA " ,"HR " =>"EU " ,"HT " =>"NA " ,"HU " =>"EU " ,"ID " =>"AS " ,"IE " =>"EU " ,"IL " =>"AS " ,"IM " =>"EU " ,"IN " =>"AS " ,"IO " =>"AS " ,"IQ " =>"AS " ,"IR " =>"AS " ,"IS " =>"EU " ,"IT " =>"EU " ,"JE " =>"EU " ,"JM " =>"NA " ,"JO " =>"AS " ,"JP " =>"AS " ,"KE " =>"AF " ,"KG " =>"AS " ,"KH " =>"AS " ,"KI " =>"OC " ,"KM " =>"AF " ,"KN " =>"NA " ,"KP " =>"AS " ,"KR " =>"AS " ,"KW " =>"AS " ,"KY " =>"NA " ,"KZ " =>"AS " ,"LA " =>"AS " ,"LB " =>"AS " ,"LC " =>"NA " ,"LI " =>"EU " ,"LK " =>"AS " ,"LR " =>"AF " ,"LS " =>"AF " ,"LT " =>"EU " ,"LU " =>"EU " ,"LV " =>"EU " ,"LY " =>"AF " ,"MA " =>"AF " ,"MC " =>"EU " ,"MD " =>"EU " ,"ME " =>"EU " ,"MF " =>"NA " ,"MG " =>"AF " ,"MH " =>"OC " ,"MK " =>"EU " ,"ML " =>"AF " ,"MM " =>"AS " ,"MN " =>"AS " ,"MO " =>"AS " ,"MP " =>"OC " ,"MQ " =>"NA " ,"MR " =>"AF " ,"MS " =>"NA " ,"MT " =>"EU " ,"MU " =>"AF " ,"MV " =>"AS " ,"MW " =>"AF " ,"MX " =>"NA " ,"MY " =>"AS " ,"MZ " =>"AF " ,"NA " =>"AF " ,"NC " =>"OC " ,"NE " =>"AF " ,"NF " =>"OC " ,"NG " =>"AF " ,"NI " =>"NA " ,"NL " =>"EU " ,"NO " =>"EU " ,"NP " =>"AS " ,"NR " =>"OC " ,"NU " =>"OC " ,"NZ " =>"OC " ,"OM " =>"AS " ,"PA " =>"NA " ,"PE " =>"SA " ,"PF " =>"OC " ,"PG " =>"OC " ,"PH " =>"AS " ,"PK " =>"AS " ,"PL " =>"EU " ,"PM " =>"NA " ,"PN " =>"OC " ,"PR " =>"NA " ,"PS " =>"AS " ,"PT " =>"EU " ,"PW " =>"OC " ,"PY " =>"SA " ,"QA " =>"AS " ,"RE " =>"AF " ,"RO " =>"EU " ,"RS " =>"EU " ,"RU " =>"EU " ,"RW " =>"AF " ,"SA " =>"AS " ,"SB " =>"OC " ,"SC " =>"AF " ,"SD " =>"AF " ,"SE " =>"EU " ,"SG " =>"AS " ,"SH " =>"AF " ,"SI " =>"EU " ,"SJ " =>"EU " ,"SK " =>"EU " ,"SL " =>"AF " ,"SM " =>"EU " ,"SN " =>"AF " ,"SO " =>"AF " ,"SR " =>"SA " ,"ST " =>"AF " ,"SV " =>"NA " ,"SY " =>"AS " ,"SZ " =>"AF " ,"TC " =>"NA " ,"TD " =>"AF " ,"TF " =>"AN " ,"TG " =>"AF " ,"TH " =>"AS " ,"TJ " =>"AS " ,"TK " =>"OC " ,"TL " =>"AS " ,"TM " =>"AS " ,"TN " =>"AF " ,"TO " =>"OC " ,"TR " =>"EU " ,"TT " =>"NA " ,"TV " =>"OC " ,"TW " =>"AS " ,"TZ " =>"AF " ,"UA " =>"EU " ,"UG " =>"AF " ,"UM " =>"OC " ,"US " =>"NA " ,"UY " =>"SA " ,"UZ " =>"AS " ,"VA " =>"EU " ,"VC " =>"NA " ,"VE " =>"SA " ,"VG " =>"NA " ,"VI " =>"NA " ,"VN " =>"AS " ,"VU " =>"OC " ,"WF " =>"OC " ,"WS " =>"OC " ,"YE " =>"AS " ,"YT " =>"AF " ,"ZA " =>"AF " ,"ZM " =>"AF " ,"ZW " =>"AF " );
13+ include "b1settings.php " ;
14+
15+ $ ttlrqtsr = $ b1_analytics_db ->get_one_row ("SELECT COUNT(*) FROM requests; " );
16+ $ total_requests = $ ttlrqtsr [0 ];
17+ if ($ total_requests == 0 ) {
18+ echo "Not enough data collected yet.<br> " ;
19+ echo "<a href= \"https://beranek1.github.io/webanalytics/ \">b1 web analytics</a> " ;
20+ $ b1_analytics_db ->close ();
21+ return ;
22+ }
23+ $ ttlvstrsr = $ b1_analytics_db ->get_one_row ("SELECT COUNT(*) FROM browsers; " );
24+ $ total_visitors = $ ttlvstrsr [0 ];
25+ $ ttlntwsr = $ b1_analytics_db ->get_one_row ("SELECT COUNT(*) FROM networks; " );
26+ $ total_networks = $ ttlntwsr [0 ];
27+ $ ttlispsr = $ b1_analytics_db ->get_one_row ("SELECT COUNT(*) FROM isps; " );
28+ $ total_isps = $ ttlispsr [0 ];
29+ $ mstrqstsr = $ b1_analytics_db ->get_rows_array ("SELECT `visitor_country`, COUNT(*) FROM requests GROUP BY `visitor_country` ORDER BY COUNT(*) DESC; " );
30+ $ top_countries = array ();
31+ $ top_continents = array ();
32+ $ total_continents = 0 ;
33+ foreach ($ mstrqstsr as $ country ) {
34+ if ($ country [0 ] != "" && $ country [0 ] != null ) {
35+ $ top_countries [$ country [0 ]] = $ country [1 ];
36+ $ continent = $ country_to_continent [strtoupper ($ country [0 ])];
37+ if (!array_key_exists ($ continent , $ top_continents )) {
38+ $ total_continents = $ total_continents + 1 ;
39+ }
40+ $ top_continents [$ continent ] = $ top_continents [$ continent ] + $ country [1 ];
41+ } else {
42+ $ top_countries ["? " ] = $ country [1 ];
43+ $ top_continents ["? " ] = $ country [1 ];
44+ }
45+ }
46+ arsort ($ top_continents );
47+ $ total_countries = 0 ;
48+ $ tpvstrsor = $ b1_analytics_db ->get_rows_array ("SELECT `country`, COUNT(*) FROM browsers GROUP BY `country` ORDER BY COUNT(*) DESC; " );
49+ $ top_countriesvo = array ();
50+ foreach ($ tpvstrsor as $ country ) {
51+ if ($ country [0 ] != "" && $ country [0 ] != null ) {
52+ $ top_countriesvo [$ country [0 ]] = $ country [1 ];
53+ $ total_countries = $ total_countries + 1 ;
54+ } else {
55+ $ top_countriesvo ["? " ] = $ country [1 ];
56+ }
57+ }
58+ $ tplngsr = $ b1_analytics_db ->get_rows_array ("SELECT `language`, COUNT(*) FROM browsers GROUP BY `language` ORDER BY COUNT(*) DESC; " );
59+ $ top_languages = array ();
60+ $ total_languages = 0 ;
61+ foreach ($ tplngsr as $ language ) {
62+ if ($ language != "" && $ language != null ) {
63+ $ top_languages [$ language [0 ]] = $ language [1 ];
64+ $ total_languages = $ total_languages + 1 ;
65+ } else {
66+ $ top_languages ["? " ] = $ language [1 ];
67+ }
68+ }
69+ $ tpusragntsr = $ b1_analytics_db ->get_rows_array ("SELECT `agent_id`, COUNT(*) FROM browsers GROUP BY `agent_id` ORDER BY COUNT(*) DESC; " );
70+ $ top_useragents = array ();
71+ foreach ($ tpusragntsr as $ useragent ) {
72+ $ top_useragents [$ useragent [0 ]] = $ useragent [1 ];
73+ }
74+ $ tpispsr = $ b1_analytics_db ->get_rows_array ("SELECT `isp_id`, COUNT(*) FROM networks GROUP BY `isp_id` ORDER BY COUNT(*) DESC; " );
75+ $ top_isps = array ();
76+ foreach ($ tpispsr as $ isp ) {
77+ $ top_isps [$ isp [0 ]] = $ isp [1 ];
78+ }
79+ $ tpurir = $ b1_analytics_db ->get_rows_array ("SELECT `uri`, COUNT(*) FROM requests GROUP BY `uri` ORDER BY COUNT(*) DESC; " );
80+ $ top_uris = array ();
81+ foreach ($ tpurir as $ uri ) {
82+ $ top_uris [$ uri [0 ]] = $ uri [1 ];
83+ }
84+ ?>
85+ <html>
86+ <head>
87+ <meta name="robots" content="noindex,nofollow">
88+ <title>b1 web analytics</title>
89+ <style>
90+ body {
91+ font-family: arial, sans-serif;
92+ max-width: 100%;
93+ }
94+ table {
95+ font-family: arial, sans-serif;
96+ border-collapse: collapse;
97+ width: 100%;
98+ }
99+ td, th {
100+ border: 1px solid #dddddd;
101+ text-align: left;
102+ padding: 8px;
103+ }
104+ tr:nth-child(even) {
105+ background-color: #dddddd;
106+ }
107+ progress {
108+ width: 100%;
109+ }
110+ @media only screen and (min-width: 600px) {
111+ div {
112+ width: 48%;
113+ float: left;
114+ padding:1%;
115+ }
116+ }
117+ </style>
118+ </head>
119+ <body>
120+ <h1>Website statistics</h1>
121+ <div>
122+ <h2>All time statistics</h2>
123+ <table>
124+ <tr><td>Total requests</td><td><?php echo $ total_requests ; ?> </td></tr>
125+ <tr><td>Total visitors</td><td><?php echo $ total_visitors ; ?> </td></tr>
126+ <tr><td>Total networks</td><td><?php echo $ total_networks ; ?> </td></tr>
127+ <tr><td>Total ISPs</td><td><?php echo $ total_isps ; ?> </td></tr>
128+ <tr><td>Total countries</td><td><?php echo $ total_countries ; ?> </td></tr>
129+ <tr><td>Total continents</td><td><?php echo $ total_continents ; ?> </td></tr>
130+ <tr><td>Total languages</td><td><?php echo $ total_languages ; ?> </td></tr>
131+ </table>
132+ </div>
133+ <div>
134+ <h2>Average visitor</h2>
135+ <table>
136+ <thead>
137+ <tr><th></th><th></th><th>proportion</th><th>chart</th></tr>
138+ </thead>
139+ <tr><td>Requests</td><td><?php echo "" .round (($ total_requests /$ total_visitors ), 2 )."" ; ?> </td></tr>
140+ <tr><td>Country</td><td><?php echo "" .array_keys ($ top_countriesvo )[0 ]."" ; ?> </td><td><?php echo "" .round ((array_values ($ top_countriesvo )[0 ] / $ total_visitors )*100 , 2 )."" ; ?> %</td><td><progress value="<?php echo "" .((array_values ($ top_countriesvo )[0 ] / $ total_visitors )*100 )."" ; ?> " max="100"></progress></td></tr>
141+ <tr><td>Language</td><td><?php echo "" .array_keys ($ top_languages )[0 ]."" ; ?> </td><td><?php echo "" .round ((array_values ($ top_languages )[0 ] / $ total_visitors )*100 , 2 )."" ; ?> %</td><td><progress value="<?php echo "" .((array_values ($ top_languages )[0 ] / $ total_visitors )*100 )."" ; ?> " max="100"></progress></td></tr>
142+ <tr><td>User agent</td><td><?php echo "" .array_keys ($ top_useragents )[0 ]."" ; ?> </td><td><?php echo "" .round ((array_values ($ top_useragents )[0 ] / $ total_visitors )*100 , 2 )."" ; ?> %</td><td><progress value="<?php echo "" .((array_values ($ top_useragents )[0 ] / $ total_visitors )*100 )."" ; ?> " max="100"></progress></td></tr>
143+ <tr><td>ISP</td><td><?php echo "" .array_keys ($ top_isps )[0 ]."" ; ?> </td><td><?php echo "" .round ((array_values ($ top_isps )[0 ] / $ total_visitors )*100 , 2 )."" ; ?> %</td><td><progress value="<?php echo "" .((array_values ($ top_isps )[0 ] / $ total_visitors )*100 )."" ; ?> " max="100"></progress></td></tr>
144+ </table>
145+ </div>
146+ <div>
147+ <h2>Countries ordered by requests</h2>
148+ <table>
149+ <thead>
150+ <tr><th>Country code</th><th>requests</th><th>proportion</th><th>chart</th></tr>
151+ </thead>
152+ <?php foreach ($ top_countries as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_requests )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_requests )*100 )."' max='100'></progress></td></tr> " ; } ?>
153+ <tr><th>Total</th><th><?php echo $ total_requests ; ?> </th></tr>
154+ </table>
155+ </div>
156+ <div>
157+ <h2>Countries ordered by visitors</h2>
158+ <table>
159+ <thead>
160+ <tr><th>Country code</th><th>visitors</th><th>proportion</th><th>chart</th></tr>
161+ </thead>
162+ <?php foreach ($ top_countriesvo as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_visitors )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_visitors )*100 )."' max='100'></progress></td></tr> " ; } ?>
163+ <tr><th>Total</th><th><?php echo $ total_visitors ; ?> </th></tr>
164+ </table>
165+ </div>
166+ <div>
167+ <h2>Continents ordered by requests</h2>
168+ <table>
169+ <thead>
170+ <tr><th>Continent code</th><th>requests</th><th>proportion</th><th>chart</th></tr>
171+ </thead>
172+ <?php foreach ($ top_continents as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_requests )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_requests )*100 )."' max='100'></progress></td></tr> " ; } ?>
173+ <tr><th>Total</th><th><?php echo $ total_requests ; ?> </th></tr>
174+ </table>
175+ </div>
176+ <div>
177+ <h2>Languages ordered by visitors</h2>
178+ <table>
179+ <thead>
180+ <tr><th>Language</th><th>visitors</th><th>proportion</th><th>chart</th></tr>
181+ </thead>
182+ <?php foreach ($ top_languages as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_visitors )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_visitors )*100 )."' max='100'></progress></td></tr> " ; } ?>
183+ <tr><th>Total</th><th><?php echo $ total_visitors ; ?> </th></tr>
184+ </table>
185+ </div>
186+ <div>
187+ <h2>Top user agents ordered by users</h2>
188+ <table>
189+ <thead>
190+ <tr><th>Agent ID</th><th>users</th><th>proportion</th><th>chart</th></tr>
191+ </thead>
192+ <?php foreach ($ top_useragents as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_visitors )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_visitors )*100 )."' max='100'></progress></td></tr> " ; } ?>
193+ <tr><th>Total</th><th><?php echo $ total_visitors ; ?> </th></tr>
194+ </table>
195+ </div>
196+ <div>
197+ <h2>Top isps ordered by networks</h2>
198+ <table>
199+ <thead>
200+ <tr><th>ISP ID</th><th>networks</th><th>proportion</th><th>chart</th></tr>
201+ </thead>
202+ <?php foreach ($ top_isps as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_networks )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_networks )*100 )."' max='100'></progress></td></tr> " ; } ?>
203+ <tr><th>Total</th><th><?php echo $ total_isps ; ?> </th></tr>
204+ </table>
205+ </div>
206+ <div>
207+ <h2>URIs/Pages ordered by requests</h2>
208+ <table>
209+ <thead>
210+ <tr><th>URI</th><th>requests</th><th>proportion</th><th>chart</th></tr>
211+ </thead>
212+ <?php foreach ($ top_uris as $ key => $ value ) { echo "<tr><td> " .$ key ."</td><td> " .$ value ."</td><td> " .round (($ value /$ total_requests )*100 , 2 )."%</td><td><progress value=' " .(($ value /$ total_requests )*100 )."' max='100'></progress></td></tr> " ; } ?>
213+ <tr><th>Total</th><th><?php echo $ total_requests ; ?> </th></tr>
214+ </table>
215+ </div>
216+ </body>
217+ <footer>
218+ <a href="https://beranek1.github.io/webanalytics/">Powered by b1 web analytics</a>
219+ </footer>
220+ </html>
221+ <?php
222+ $ b1_analytics_db ->close ();
223+ ?>
0 commit comments