| [ PHPXref.com ] | [ Generated: Sun Jul 20 16:40:17 2008 ] | [ BLOG:CMS 4.1.3 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BLOG:CMS: PHP/MySQL Personal Content Management System (CMS) 4 * http://blogcms.com/ 5 * ---------------------------------------------------------------- 6 * 7 * Copyright (C) 2003-2005 Radek HULÁN 8 * http://hulan.cz/contact/ 9 * 10 * ---------------------------------------------------------------- 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; either version 2 14 * of the License, or (at your option) any later version. 15 **/ 16 17 include('./cfg.php'); 18 19 /* already logged-in? */ 20 if (!$member->isLoggedIn() || !$member->isAdmin()) doError("You are not logged-in!"); 21 22 sql_connect(true); 23 24 25 /* generate doctype */ 26 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"; 27 echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"><head>\n"; 28 echo "<meta http-equiv=\"Pragma\" content=\"no-cache\"/>\n"; 29 echo "<meta http-equiv=\"Cache-Control\" content=\"no-cache, must-revalidate\"/>\n"; 30 echo "<meta http-equiv=\"Expires\" content=\"-1\"/>\n"; 31 echo "<link href=\"admin/styles/list.css\" rel=\"stylesheet\" rev=\"1.0\"/>\n"; 32 echo "<title>statistics</title>\n"; 33 echo "</head><body>\n"; 34 echo "<div>\n"; 35 echo "<h1>Simple statistics / log for your blog</h1>\n"; 36 37 /* set date variables */ 38 $FROMMDAY=date("d"); 39 $FROMMMONTH=date("m"); 40 $FROMMYEAR=date("y"); 41 if(isset($_POST['FROMMYDAY'])){$FROMMDAY=$_POST['FROMMYDAY'];}; 42 if(isset($_POST['FROMMYMONTH'])){$FROMMMONTH=$_POST['FROMMYMONTH'];}; 43 if(isset($_POST['FROMMYYEAR'])){$FROMMYEAR=$_POST['FROMMYYEAR'];}; 44 if(strlen($FROMMDAY)==1){$FROMMDAY="0$FROMMDAY";}; 45 if(strlen($FROMMMONTH)==1){$FROMMMONTH="0$FROMMMONTH";}; 46 if(strlen($FROMMYEAR)==1){$FROMMYEAR="0$FROMMYEAR";}; 47 48 $TOMDAY=date("d"); 49 $TOMMONTH=date("m"); 50 $TOMYEAR=date("y"); 51 if(isset($_POST['TOMYDAY'])){$TOMDAY=$_POST['TOMYDAY'];}; 52 if(isset($_POST['TOMYMONTH'])){$TOMMONTH=$_POST['TOMYMONTH'];}; 53 if(isset($_POST['TOMYYEAR'])){$TOMYEAR=$_POST['TOMYYEAR'];}; 54 if(strlen($TOMDAY)==1){$TOMDAY="0$TOMDAY";}; 55 if(strlen($TOMMONTH)==1){$TOMMONTH="0$TOMMONTH";}; 56 if(strlen($TOMYEAR)==1){$TOMYEAR="0$TOMYEAR";}; 57 58 /* how much records to display */ 59 $HOWMUCH="20"; 60 if(isset($_POST['RECORDS'])){$HOWMUCH=$_POST['RECORDS'];} 61 62 /* filter for IP and DNS? */ 63 $MYFILTERIP=''; 64 if(isset($_POST['FILTERIP'])){$MYFILTERIP=$_POST['FILTERIP'];} 65 $MYFILTERDNS=''; 66 if(isset($_POST['FILTERDNS'])){$MYFILTERDNS=$_POST['FILTERDNS'];} 67 68 /* delete stats */ 69 $time= mktime (0,0,0,date("m"),date("d")-3,date("Y")); 70 $old= strftime("%m/%d/%y",$time); 71 72 /* delete log?? */ 73 if(isset($_POST['MYCLEAR'])){ 74 if($_POST['MYCLEAR']=="YES"){ 75 $deleting=strftime("%y%m%d",$time); 76 $query="DELETE FROM ".sql_table('httplog')." WHERE XDATE<'$deleting'"; 77 sql_query($query); 78 echo '<h3>Everything older than '.$old.' was deleted..</strong></h3>'."\n"; 79 } 80 } 81 82 /* GET filter parameters? */ 83 if (isset($_GET['FADDR'])){ 84 $MYFILTERIP=$_GET['FADDR']; 85 } 86 if (isset($_GET['FFROM'])){ 87 $FROMMDAY=substr($_GET['FFROM'],4,2); 88 $FROMMMONTH=substr($_GET['FFROM'],2,2); 89 $FROMMYEAR=substr($_GET['FFROM'],0,2); 90 } 91 if (isset($_GET['FTO'])){ 92 $TOMDAY=substr($_GET['FTO'],4,2); 93 $TOMMONTH=substr($_GET['FTO'],2,2); 94 $TOMYEAR=substr($_GET['FTO'],0,2); 95 } 96 97 $searchfilter=''; 98 if($MYFILTERIP!=''){ 99 $searchfilter=" $searchfilter AND (INSTR(XADDR,'$MYFILTERIP')>0) "; 100 } 101 if($MYFILTERDNS!=''){ 102 $searchfilter=" $searchfilter AND (INSTR(XDNS,'$MYFILTERDNS')>0) "; 103 } 104 105 echo "<form method=\"post\" action=\"list.php\">\n"; 106 echo "<fieldset><legend>From:</legend>\n"; 107 echo "<label for=\"FROMMYDAY\"><strong>Day: </strong></label><input class=\"formfield\" type=\"text\" id=\"FROMMYDAY\" name=\"FROMMYDAY\" size=\"2\" maxlength=\"2\" value=\"$FROMMDAY\"> \n"; 108 echo "<label for=\"FROMMYMONTH\"><strong>Month: </strong></label><input class=\"formfield\" type=\"text\" id=\"FROMMYMONTH\" name=\"FROMMYMONTH\" size=\"2\" maxlength=\"2\" value=\"$FROMMMONTH\"> \n"; 109 echo "<label for=\"FROMMYYEAR\"><strong>Year: </strong></label><input class=\"formfield\" type=\"text\" id=\"FROMMYYEAR\" name=\"FROMMYYEAR\" size=\"2\" maxlength=\"2\" value=\"$FROMMYEAR\"> \n"; 110 echo "</fieldset>\n"; 111 echo "<fieldset><legend>To:</legend>\n"; 112 echo "<label for=\"TOMYDAY\"><strong>Day: </strong></label><input class=\"formfield\" type=\"text\" id=\"TOMYDAY\" name=\"TOMYDAY\" size=\"2\" maxlength=\"2\" value=\"$TOMDAY\"> \n"; 113 echo "<label for=\"TOMYMONTH\"><strong>Month: </strong></label><input class=\"formfield\" type=\"text\" id=\"TOMYMONTH\" name=\"TOMYMONTH\" size=\"2\" maxlength=\"2\" value=\"$TOMMONTH\"> \n"; 114 echo "<label for=\"TOMYYEAR\"><strong>Year: </strong></label><input class=\"formfield\" type=\"text\" id=\"TOMYYEAR\" name=\"TOMYYEAR\" size=\"2\" maxlength=\"2\" value=\"$TOMYEAR\"><br/>\n"; 115 116 echo "<label for=\"MYCLEAR\">Delete everything older than $old? Type 'YES' to delete and press button: </label><input class=\"formfield\" type=\"text\" id=\"MYCLEAR\" name=\"MYCLEAR\" size=\"3\" maxlength=\"3\" value=\"NO\"><br/>\n"; 117 118 echo "<label for=\"FILTERIP\">Filter for IP: </label><input class=\"formfield\" type=\"text\" id=\"FILTERIP\" name=\"FILTERIP\" size=\"15\" maxlength=\"20\" value=\"$MYFILTERIP\"> \n"; 119 echo "<label for=\"FILTERDNS\">Filter for DNS: </label><input class=\"formfield\" type=\"text\" id=\"FILTERDNS\" name=\"FILTERDNS\" size=\"20\" maxlength=\"60\" value=\"$MYFILTERDNS\"><br/>\n"; 120 121 echo "<label for=\"RECORDS\">What is the maximum number of records you want to list? </label><input class=\"formfield\" type=\"text\" id=\"RECORDS\" name=\"RECORDS\" size=\"4\" maxlength=\"4\" value=\"$HOWMUCH\"><br/>\n"; 122 123 echo "<select name=\"LISTSELECT\">\n"; 124 $_POST['LISTSELECT']=='4' ? $deff=" selected" : $deff=''; echo "<option value=\"4\" $deff>unique IP addresses</option>\n"; 125 $_POST['LISTSELECT']=='1' ? $deff=" selected" : $deff=''; echo "<option value=\"1\" $deff>daily list, default</option>\n"; 126 $_POST['LISTSELECT']=='2' ? $deff=" selected" : $deff=''; echo "<option value=\"2\" $deff>group by IP address</option>\n"; 127 $_POST['LISTSELECT']=='3' ? $deff=" selected" : $deff=''; echo "<option value=\"3\" $deff>group by browser agent</option>\n"; 128 echo "</select>\n"; 129 130 echo "<input type=\"submit\" value=\"View statistics\"/>\n"; 131 echo "</fieldset>\n"; 132 echo "</form>\n"; 133 134 /* -------------- 1 ---------- */ 135 if($_POST['LISTSELECT']=='1' || $_GET['FTYPE']=='1'){ 136 echo "<h3>Daily list sorted, in descending order, by date and time</h3>\n"; 137 echo "<table>\n"; 138 echo '<tr>'."\n"; 139 echo '<th width="4%">ID</th>'."\n"; 140 echo '<th width="9%">Date</th>'."\n"; 141 echo '<th width="7%">Time</th>'."\n"; 142 echo '<th width="10%">IP</th>'."\n"; 143 echo '<th width="20%">DNS</th>'."\n"; 144 echo '<th width="10%">Agent</th>'."\n"; 145 echo '<th width="20%">URI</th>'."\n"; 146 echo '<th width="20%">Referrer</th>'."\n"; 147 echo '</tr>'."\n"; 148 $frommydate="$FROMMYEAR$FROMMMONTH$FROMMDAY"; 149 $tomydate= "$TOMYEAR$TOMMONTH$TOMDAY"; 150 $query = sql_query("select * from ".sql_table('httplog')." where (XDATE>='$frommydate') and (XDATE<='$tomydate') $searchfilter order by UID desc LIMIT 0,$HOWMUCH"); 151 $num=1; 152 $style='two'; 153 while ( $msg = sql_fetch_array( $query )) { 154 $style=='one' ? $style='two' : $style='one'; 155 echo '<tr>'."\n"; 156 echo '<td class="'.$style.'">'.$num.'</td>'."\n"; 157 echo '<td class="'.$style.'">'.substr($msg['XDATE'],2,2).'/'.substr($msg['XDATE'],4,2).'</td>'."\n"; 158 echo '<td class="'.$style.'">'.$msg['XTIME'].' </td>'."\n"; 159 echo '<td class="'.$style.'">'.$msg['XADDR'].' </td>'."\n"; 160 echo '<td class="'.$style.'"><a href="./list.php?FTYPE=1&FADDR='.$msg['XADDR'].'&FFROM='.$frommydate.'&FTO='.$tomydate.'">'.$msg['XDNS'].' </a></td>'."\n"; 161 echo '<td class="'.$style.'">'.$msg['XAGENT'].' </td>'."\n"; 162 echo '<td class="'.$style.'">'.$msg['XPATH'].' </td>'."\n"; 163 echo '<td class="'.$style.'"><a href="'.$msg['XREFERER'].'">'.$msg['XREFERER'].' </a></td>'."\n"; 164 echo '</tr>'."\n"; 165 $num++; 166 }; 167 echo "</table>"."\n"; 168 } 169 /* end --1-- */ 170 171 /* -------------- 2 ---------- */ 172 if($_POST['LISTSELECT']=='2'){ 173 echo "<h3>Daily list grouped by IP address, and sorted by date and time</h3>"."\n"; 174 echo "<table>"."\n"; 175 $frommydate="$FROMMYEAR$FROMMMONTH$FROMMDAY"; 176 $tomydate= "$TOMYEAR$TOMMONTH$TOMDAY"; 177 $query = sql_query("select * from ".sql_table('httplog')." where (XDATE>='$frommydate') and (XDATE<='$tomydate') $searchfilter order by XADDR asc, UID desc LIMIT 0,$HOWMUCH"); 178 $lastaddr=""; 179 $ipnum=0; 180 $style='two'; 181 while ( $msg = sql_fetch_array( $query )) { 182 if ($lastaddr!=$msg['XADDR']){ 183 $num=1; 184 $lastaddr = $msg['XADDR']; 185 /* header */ 186 echo '<tr>'."\n"; 187 $ipnum++; 188 echo '<th colspan="4">'.$ipnum.'</th>'."\n"; 189 echo '<th>'.$msg['XADDR'].'</th>'."\n"; 190 echo '<th>'.$msg['XDNS'].'</th>'."\n"; 191 echo '</tr>'."\n"; 192 /* ip and dns */ 193 echo '<tr>'."\n"; 194 echo '<th><strong>ID</strong></th>'."\n"; 195 echo '<th><strong>Date</strong></th>'."\n"; 196 echo '<th><strong>Time</strong></th>'."\n"; 197 echo '<th><strong>Browser</strong></th>'."\n"; 198 echo '<th><strong>URI</strong></th>'."\n"; 199 echo '<th><strong>Referrer</strong></th>'."\n"; 200 echo '</tr>'."\n"; 201 $style='two'; 202 } 203 /* details */ 204 $style=='one' ? $style='two' : $style='one'; 205 echo '<tr>'."\n"; 206 echo '<td class="'.$style.'">'.$num.'</td>'."\n"; 207 echo '<td class="'.$style.'">'.substr($msg['XDATE'],2,2).'/'.substr($msg['XDATE'],4,2).'</td>'."\n"; 208 echo '<td class="'.$style.'">'.$msg['XTIME'].' </td>'."\n"; 209 echo '<td class="'.$style.'">'.$msg['XAGENT'].' </td>'."\n"; 210 echo '<td class="'.$style.'">'.$msg['XPATH'].' </td>'."\n"; 211 echo '<td class="'.$style.'"><a href="'.$msg['XREFERER'].'">'.$msg['XREFERER'].' </a></td>'."\n"; 212 echo '</tr>'."\n"; 213 $num++; 214 }; 215 echo "</table>"."\n"; 216 } 217 /* end --2-- */ 218 219 /* -------------- 3 ---------- */ 220 if($_POST['LISTSELECT']=='3'){ 221 echo "<h3>Information about browsers</h3>"."\n"; 222 echo "<table>"."\n"; 223 echo '<tr>'."\n"; 224 echo '<th width="50%">User agent</th>'."\n"; 225 echo '<th width="50%">Total views</th>'."\n"; 226 echo '</tr>'."\n"; 227 $frommydate="$FROMMYEAR$FROMMMONTH$FROMMDAY"; 228 $tomydate= "$TOMYEAR$TOMMONTH$TOMDAY"; 229 $query = sql_query("select count(*) as XTOTAL, max(XAGENT) as XAG from ".sql_table('httplog')." where (XDATE>='$frommydate') and (XDATE<='$tomydate') $searchfilter group by XAGENT order by XTOTAL desc"); 230 $num=1; 231 $style='two'; 232 while ( $msg = sql_fetch_array( $query )) { 233 $style=='one' ? $style='two' : $style='one'; 234 echo '<tr>'."\n"; 235 echo '<td class="'.$style.'">'.$msg['XAG'].' </td>'."\n"; 236 echo '<td class="'.$style.'">'.$msg['XTOTAL'].' </td>'."\n"; 237 echo '</tr>'."\n"; 238 $num++; 239 }; 240 echo "</table>"."\n"; 241 } 242 /* end --3-- */ 243 244 /* -------------- 4 ---------- */ 245 if($_POST['LISTSELECT']=='4'){ 246 echo "<h3>Daily unique IP address list, sorted, in descending order, by date and time</h3>"."\n"; 247 echo "<table>"."\n"; 248 echo '<tr>'."\n"; 249 echo '<th width="4%">ID</th>'."\n"; 250 echo '<th width="9%">Date</th>'."\n"; 251 echo '<th width="7%">Time</th>'."\n"; 252 echo '<th width="10%">IP</th>'."\n"; 253 echo '<th width="20%">DNS</th>'."\n"; 254 echo '<th width="10%">Agent</th>'."\n"; 255 echo '<th width="5%">Views</th>'."\n"; 256 echo '<th width="15%">URI</th>'."\n"; 257 echo '<th width="20%">Referrer</th>'."\n"; 258 echo '</tr>'."\n"; 259 $frommydate="$FROMMYEAR$FROMMMONTH$FROMMDAY"; 260 $tomydate= "$TOMYEAR$TOMMONTH$TOMDAY"; 261 $fullquery=sql_query("select MIN(UID) AS XUID, COUNT(UID) AS XTOTAL from ".sql_table('httplog')." where (XDATE>='$frommydate') and (XDATE<='$tomydate') $searchfilter group by XADDR order by UID DESC LIMIT 0,$HOWMUCH"); 262 $num=1; 263 $style='two'; 264 while ( $fullmsg = sql_fetch_array( $fullquery )) { 265 $style=='one' ? $style='two' : $style='one'; 266 $xuid=$fullmsg['XUID']; 267 $query = sql_query("select * from ".sql_table('httplog')." where UID='$xuid'"); 268 $msg = sql_fetch_array( $query ); 269 echo '<tr>'."\n"; 270 echo '<td class="'.$style.'">'.$num.'</td>'."\n"; 271 echo '<td class="'.$style.'">'.substr($msg['XDATE'],2,2).'/'.substr($msg['XDATE'],4,2).'</td>'."\n"; 272 echo '<td class="'.$style.'">'.$msg['XTIME'].' </td>'."\n"; 273 echo '<td class="'.$style.'">'.$msg['XADDR'].' </td>'."\n"; 274 echo '<td class="'.$style.'"><a href="./list.php?FTYPE=1&FADDR='.$msg['XADDR'].'&FFROM='.$frommydate.'&FTO='.$tomydate.'">'.$msg['XDNS'].' </a></td>'."\n"; 275 echo '<td class="'.$style.'">'.$msg['XAGENT'].' </td>'."\n"; 276 echo '<td class="'.$style.'">'.$fullmsg['XTOTAL'].' </td>'."\n"; 277 echo '<td class="'.$style.'">'.$msg['XPATH'].' </td>'."\n"; 278 echo '<td class="'.$style.'"><a href="'.$msg['XREFERER'].'">'.$msg['XREFERER'].' </a></td>'."\n"; 279 echo '</tr>'."\n"; 280 $num++; 281 }; 282 echo "</table>"."\n"; 283 } 284 /* end --4-- */ 285 286 if( (!isset($_POST['LISTSELECT'])) && (!isset($_GET['FTYPE'])) ) echo "<h3>Please select statistics you want to view in drop-down menu and press View button.</h3>"."\n"; 287 288 /* closing... */ 289 echo "<p id='copyright'>Copyright © <a href=\"http://hulan.cz/blog/\">Radek Hulán</a></p>"."\n"; 290 echo "</div>\n</body></html>"; 291 292 sql_disconnect(); 293 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |