-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgm-site_stats.inc.php
367 lines (274 loc) · 15.8 KB
/
pgm-site_stats.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
error_reporting(E_PARSE);
if($_GET['_SESSION'] != '' || $_POST['_SESSION'] != '' || $_COOKIE['_SESSION'] != '') { exit; }
error_reporting(E_PARSE);
###############################################################################
## Soholaunch(R) Site Management Tool
## Version 4.5
##
## Author: Mike Johnston [mike.johnston@soholaunch.com]
## Homepage: http://www.soholaunch.com
## Bug Reports: http://bugzilla.soholaunch.com
## Release Notes: sohoadmin/build.dat.php
###############################################################################
##############################################################################
## COPYRIGHT NOTICE
## Copyright 1999-2003 Soholaunch.com, Inc. and Mike Johnston
## Copyright 2003-2007 Soholaunch.com, Inc.
## All Rights Reserved.
##
## This script may be used and modified in accordance to the license
## agreement attached (license.txt) except where expressly noted within
## commented areas of the code body. This copyright notice and the comments
## comments above and below must remain intact at all times. By using this
## code you agree to indemnify Soholaunch.com, Inc, its coporate agents
## and affiliates from any liability that might arise from its use.
##
## Selling the code for this program without prior written consent is
## expressly forbidden and in violation of Domestic and International
## copyright laws.
###############################################################################
# EXPLOIT PREVENTION: Skip all of this if page request is url
if ( !eregi("^http", $_REQUEST['pr']) ) {
// **********************************************************
// STEP 1: SETUP MONTH & TIME VARIABLES FOR THIS TRANSACTION
// **********************************************************
$st_db_tDATE = date("Y-m-d");
$st_db_tMONTH = date("F");
$st_db_tHOUR = date("H");
$st_db_tDOW = date("j");
$st_db_tYEAR = date("Y");
// **********************************************************
// STEP 2: READ CLIENT DATA WHEN AVAILABLE
// **********************************************************
// ------------------------------------------------------------------------------------
// $statpage :: Tells the system WHAT to log as a hit; unique or otherwise. This is
// mostly for use within other modules. Oddly enough, we must compensate
// for database searches and calendar searches (via includes) through the
// normal page builder pgm. So let's make sure it takes precedence over
// the "$pageRequest" variable.
// ------------------------------------------------------------------------------------
if ($statpage == "") { $st_db_pgNAME = $pageRequest; } else { $st_db_pgNAME = $statpage; }
$st_db_ipADDR = $REMOTE_ADDR; // Site Visitor IP
$st_db_REFER = $HTTP_REFERER; // Refering Website
$st_db_tBROWSER = $HTTP_USER_AGENT; // Browser In Use
$real_date = date("Y-m-d"); // Format for SQL date field (today)
if (eregi("$dot_com", $st_db_REFER)) { $st_db_REFER = "(Internal)"; } // If referer contains dot_com var, this was an internal link
if (eregi("$this_ip", $st_db_REFER)) { $st_db_REFER = "(Internal)"; } // If referer contains server ipaddr, this was an internal link
if ($st_db_REFER == "") { $st_db_REFER = "(Direct)"; } // If no referer var is present; must have typed URL in browser
if ($st_db_pgNAME == "") { $st_db_pgNAME = startpage(false); } // If not pr var was passed; must have been direct entry
$st_db_pgNAME = eregi_replace("_", " ", $st_db_pgNAME); // Replace any underscores in Page Name Var
###########################################
## SPLIT REFERER URL INTO MAIN DNS FOR LOG
###########################################
// Commented out for V4 - We want to see what "Searches" were performed
// When coming from search engines
// if (eregi("http://", $st_db_REFER)) {
// $st_db_tmp = split("/", $st_db_REFER);
// $st_db_REFER = $st_db_tmp[0] . "//" . $st_db_tmp[2];
// }
// **********************************************************
// STEP 3: IF PAGE WAS ACCESSED WITH #; CONVERT TO NAME
// **********************************************************
$l = strlen($st_db_pgNAME);
$zz = 0;
$st_db_tmpman = 0;
while($zz != $l) {
$stdb_temp = substr($st_db_pgNAME, $zz, 1);
if (eregi("[0-9]", $stdb_temp)) { $st_db_tmpman++; }
$zz++;
}
if ($st_db_tmpman == $l) {
$realname = mysql_query("SELECT page_name FROM site_pages WHERE link = '$st_db_pgNAME'");
while ($joe = mysql_fetch_array ($realname)) {
$st_db_pgNAME = $joe["page_name"];
}
}
// *****************************************************************
// STEP 4: HAS THE NEW DATATABLES BEEN CREATED? IF NOT, CREATE THEM
// *****************************************************************
// Version 4.0 adds the SESSION field to our log tables for more
// acurate tracking. This is the first version to utilize sessions
// to track movement throughout the entire web site.
// mysql_query("DROP TABLE STATS_TOP25");
// mysql_query("DROP TABLE STATS_BYDAY");
// mysql_query("DROP TABLE STATS_BYHOUR");
// mysql_query("DROP TABLE STATS_REFER");
// mysql_query("DROP TABLE STATS_UNIQUE");
// mysql_query("DROP TABLE STATS_BROWSER");
$st_db_result = mysql_list_tables($db_name);
$st_db_match = 0;
$stdb_i = 0;
while ($stdb_i <= mysql_num_rows ($st_db_result)) {
$tb_names[$stdb_i] = mysql_tablename($st_db_result, $stdb_i);
if ($tb_names[$stdb_i] == "STATS_TOP25") { $st_db_match++; }
if ($tb_names[$stdb_i] == "STATS_BYDAY") { $st_db_match++; }
if ($tb_names[$stdb_i] == "STATS_BYHOUR") { $st_db_match++; }
if ($tb_names[$stdb_i] == "STATS_REFER") { $st_db_match++; }
if ($tb_names[$stdb_i] == "STATS_UNIQUE") { $st_db_match++; }
if ($tb_names[$stdb_i] == "STATS_BROWSER") { $st_db_match++; }
$stdb_i++;
}
if ($st_db_match != 6) {
mysql_db_query("$db_name","CREATE TABLE STATS_TOP25 (PriKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Month CHAR(25),Year INT(4),Page CHAR(25), Hits INT(25), SESSION CHAR(255), Real_Date DATE)");
mysql_db_query("$db_name","CREATE TABLE STATS_BYDAY (PriKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Month CHAR(25),Year INT(4),Day CHAR(25), Hits INT(25), SESSION CHAR(255), Real_Date DATE)");
mysql_db_query("$db_name","CREATE TABLE STATS_BYHOUR (PriKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Month CHAR(25),Year INT(4),Hour CHAR(25), Hits INT(25), SESSION CHAR(255), Real_Date DATE)");
mysql_db_query("$db_name","CREATE TABLE STATS_REFER (PriKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Month CHAR(25),Year INT(4),Refer CHAR(255), Hits INT(25), SESSION CHAR(255), Real_Date DATE)");
mysql_db_query("$db_name","CREATE TABLE STATS_UNIQUE (PriKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Month CHAR(25),Year INT(4), IP CHAR(25),Hour CHAR(25), Hits INT(25), Browser CHAR(100), SESSION CHAR(255), Real_Date DATE)");
mysql_db_query("$db_name","CREATE TABLE STATS_BROWSER (PriKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Month CHAR(25),Year INT(4),Browser CHAR(255), Hits INT(25), SESSION CHAR(255), Real_Date DATE)");
}
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# INSERTED: START of modified code to add max, min and avg users per hour
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
$fields = mysql_list_fields($db_name, 'STATS_BYHOUR');
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {$field_array[] = mysql_field_name($fields, $i);}
if (!in_array('Max_Users', $field_array))
{
$result = mysql_query("ALTER TABLE STATS_BYHOUR ADD Min_Users INT(8)");
$result = mysql_query("ALTER TABLE STATS_BYHOUR ADD Max_Users INT(8)");
$result = mysql_query("ALTER TABLE STATS_BYHOUR ADD Avg_Users FLOAT");
}
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# END of modified code to add max, min and avg users per hour
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
// *****************************************************************
// STEP 5: CALCULATE AND dB TOP 25 PAGE TABLE
// *****************************************************************
$st_db_pgNAME = substr($st_db_pgNAME, 0, 25);
## FIRST, PULL THIS MONTH AND THIS PAGENAME TOTAL HITS
#######################################################
$st_db_result = mysql_query("SELECT PriKey, Hits FROM STATS_TOP25 WHERE Page = '$st_db_pgNAME' AND Month = '$st_db_tMONTH' AND Year = '$st_db_tYEAR'");
$st_db_rtn = mysql_num_rows($st_db_result);
## IF THIS PAGE EXISTS IN TABLE, UPDATE RECORD TO REFLECT NEW HIT
##################################################################
if ($st_db_rtn > 0) {
while ($st_db_row = mysql_fetch_array ($st_db_result)) {
$stdb_PriKey = $st_db_row[PriKey];
$dB_Cur_Num = $st_db_row[Hits];
}
$dB_Cur_Num++;
mysql_query("UPDATE STATS_TOP25 SET Hits = '$dB_Cur_Num' WHERE PriKey = '$stdb_PriKey'");
} else {
## IF PAGE DOES NOT EXIST, CREATE NEW RECORD ENTRY AND COUNT
#############################################################
mysql_query("INSERT INTO STATS_TOP25 VALUES('NULL','$st_db_tMONTH','$st_db_tYEAR','$st_db_pgNAME','1','$PHPSESSID','$real_date')");
}
// *****************************************************************
// STEP 6: CALCULATE AND dB BY DAY STATS TABLE
// *****************************************************************
## FIRST, PULL THIS MONTH AND THIS DAY TOTAL HITS
#######################################################
$st_db_result = mysql_query("SELECT PriKey, Hits FROM STATS_BYDAY WHERE Day = '$st_db_tDOW' AND Month = '$st_db_tMONTH' AND Year = '$st_db_tYEAR'");
$st_db_rtn = mysql_num_rows($st_db_result);
## IF THIS DAY EXISTS IN TABLE, UPDATE RECORD TO REFLECT NEW HIT
##################################################################
if ($st_db_rtn > 0) {
while ($st_db_row = mysql_fetch_array ($st_db_result)) {
$stdb_PriKey = $st_db_row[PriKey];
$dB_Cur_Num = $st_db_row[Hits];
}
$dB_Cur_Num++;
mysql_query("UPDATE STATS_BYDAY SET Hits = '$dB_Cur_Num' WHERE PriKey = '$stdb_PriKey'");
} else {
## IF DAY DOES NOT EXIST, CREATE NEW RECORD ENTRY AND COUNT
#############################################################
mysql_query("INSERT INTO STATS_BYDAY VALUES('NULL','$st_db_tMONTH','$st_db_tYEAR','$st_db_tDOW','1','$PHPSESSID','$real_date')");
}
// *****************************************************************
// STEP 7: CALCULATE AND dB BY HOUR STATS TABLE
// *****************************************************************
## FIRST, PULL THIS MONTH AND THIS HOUR TOTAL HITS
#######################################################
// $st_db_result = mysql_query("SELECT * FROM STATS_BYHOUR WHERE Hour = '$st_db_tHOUR' AND Month = '$st_db_tMONTH' AND Year = '$st_db_tYEAR'");
$st_db_result = mysql_query("SELECT * FROM STATS_BYHOUR WHERE Hour = '$st_db_tHOUR' AND Real_Date = '$st_db_tDATE'");
$st_db_rtn = mysql_num_rows($st_db_result);
## IF THIS HOUR EXISTS IN TABLE, UPDATE RECORD TO REFLECT NEW HIT
##################################################################
if ($st_db_rtn > 0) {
while ($st_db_row = mysql_fetch_array ($st_db_result)) {
$stdb_PriKey = $st_db_row[PriKey];
$dB_Cur_Num = $st_db_row[Hits];
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# REPLACED: START of replacement code to add max, min and avg users per hour
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
$db_Avg_Users = (( $st_db_row[Avg_Users] * $st_db_row[Hits] ) + $useronline ) / ( $st_db_row[Hits] + 1 );
$db_Min_Users = min($useronline, $st_db_row[Min_Users]);
$db_Max_Users = max($useronline, $st_db_row[Max_Users]);
}
$dB_Cur_Num++;
mysql_query("UPDATE STATS_BYHOUR SET Hits = '$dB_Cur_Num', Min_Users = '$db_Min_Users',
Max_Users = '$db_Max_Users', Avg_Users = '$db_Avg_Users' WHERE PriKey = '$stdb_PriKey'") or die (mysql_error());
} else {
## IF HOUR DOES NOT EXIST, CREATE NEW RECORD ENTRY AND COUNT
#############################################################
mysql_query("INSERT INTO STATS_BYHOUR VALUES('NULL','$st_db_tMONTH','$st_db_tYEAR','$st_db_tHOUR','1','$PHPSESSID','$real_date','$useronline','$useronline','$useronline')") or die (mysql_error());
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# END of replacement code to add max, min and avg users per hour
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
}
// *****************************************************************
// STEP 8: CALCULATE AND dB REFERRER STATS TABLE
// *****************************************************************
## FIRST, PULL THIS MONTH AND THIS REFERRERS TOTAL HITS
########################################################
$st_db_result = mysql_query("SELECT PriKey, Hits FROM STATS_REFER WHERE Refer = '$st_db_REFER' AND Month = '$st_db_tMONTH' AND Year = '$st_db_tYEAR'");
$st_db_rtn = mysql_num_rows($st_db_result);
## IF THIS REF EXISTS IN TABLE, UPDATE RECORD TO REFLECT NEW HIT
##################################################################
if ($st_db_rtn > 0) {
while ($st_db_row = mysql_fetch_array ($st_db_result)) {
$stdb_PriKey = $st_db_row[PriKey];
$dB_Cur_Num = $st_db_row[Hits];
}
$dB_Cur_Num++;
mysql_query("UPDATE STATS_REFER SET Hits = '$dB_Cur_Num' WHERE PriKey = '$stdb_PriKey'");
} else {
## IF PAGE DOES NOT EXIST, CREATE NEW RECORD ENTRY AND COUNT
#############################################################
mysql_query("INSERT INTO STATS_REFER VALUES('NULL','$st_db_tMONTH','$st_db_tYEAR','$st_db_REFER','1','$PHPSESSID','$real_date')");
}
// *****************************************************************
// STEP 9: CALCULATE AND dB UNIQE VISITOR NUMBERS
// *****************************************************************
## FIRST, PULL THIS MONTH AND THIS REFERRERS TOTAL HITS
########################################################
$st_db_result = mysql_query("SELECT PriKey, Hits FROM STATS_UNIQUE WHERE IP = '$st_db_ipADDR' AND Month = '$st_db_tMONTH' AND Year = '$st_db_tYEAR' AND Hour = '$st_db_tHOUR'");
$st_db_rtn = mysql_num_rows($st_db_result);
## IF THIS REF EXISTS IN TABLE, UPDATE RECORD TO REFLECT NEW HIT
##################################################################
if ($st_db_rtn > 0) {
while ($st_db_row = mysql_fetch_array ($st_db_result)) {
$stdb_PriKey = $st_db_row[PriKey];
$dB_Cur_Num = $st_db_row[Hits];
}
$dB_Cur_Num++;
mysql_query("UPDATE STATS_UNIQUE SET Hits = '$dB_Cur_Num' WHERE PriKey = '$stdb_PriKey'");
} else {
## IF PAGE DOES NOT EXIST, CREATE NEW RECORD ENTRY AND COUNT
#############################################################
mysql_query("INSERT INTO STATS_UNIQUE VALUES('NULL','$st_db_tMONTH','$st_db_tYEAR','$st_db_ipADDR','$st_db_tHOUR','1','$st_db_tBROWSER','$PHPSESSID','$real_date')");
}
// *****************************************************************
// STEP 10: CALCULATE AND dB BROWSER NUMBERS
// *****************************************************************
## FIRST, PULL THIS MONTH AND THIS REFERRERS TOTAL HITS
########################################################
$st_db_result = mysql_query("SELECT PriKey, Hits FROM STATS_BROWSER WHERE Browser = '$st_db_tBROWSER' AND Month = '$st_db_tMONTH' AND Year = '$st_db_tYEAR'");
$st_db_rtn = mysql_num_rows($st_db_result);
## IF THIS REF EXISTS IN TABLE, UPDATE RECORD TO REFLECT NEW HIT
##################################################################
if ($st_db_rtn > 0) {
while ($st_db_row = mysql_fetch_array ($st_db_result)) {
$stdb_PriKey = $st_db_row[PriKey];
$dB_Cur_Num = $st_db_row[Hits];
}
$dB_Cur_Num++;
mysql_query("UPDATE STATS_BROWSER SET Hits = '$dB_Cur_Num' WHERE PriKey = '$stdb_PriKey'");
} else {
## IF PAGE DOES NOT EXIST, CREATE NEW RECORD ENTRY AND COUNT
#############################################################
mysql_query("INSERT INTO STATS_BROWSER VALUES('NULL','$st_db_tMONTH','$st_db_tYEAR','$st_db_tBROWSER','1','$PHPSESSID','$real_date')");
}
} // End if !eregi(http, pr)
?>