Changes between Initial Version and Version 1 of PlugIns/PHP


Ignore:
Timestamp:
10/04/12 09:01:18 (12 years ago)
Author:
sherbold
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PlugIns/PHP

    v1 v1  
     1= PHPMonitor = 
     2 
     3The PHPMonitor is a small PHP script with has to be pre-prended to all other PHP scripts of a website. This can be done either manually (unreliable) or by configuring the php.ini file of a server appropriatly (not always possible). The script relies on a cookie for the user identification to be available thorugh the [http://httpd.apache.org/docs/2.2/mod/mod_usertrack.html Apache module mod_usertrack]. 
     4 
     5{{{ 
     6#!php 
     7<?php 
     8  /* 
     9   * Usage monitoring script for PHP web applications. 
     10   * Requires the apache modules mod_usertrack to provide 
     11   * a cookie for user identification. 
     12   */ 
     13  $log_dir = dirname( __FILE__)."/"; 
     14  $log_name = "usage.log"; 
     15  $cookie_name = "swe_informatik_uni-goettingen_de"; 
     16 
     17  $postkeys = ""; 
     18 
     19  while (list($key, $value) = each($_POST)) { 
     20    $postkeys = $postkeys." ".$key; 
     21  } 
     22  if( $_SERVER['HTTP_REFERER']=='' ) { 
     23    $referer = '-'; 
     24  } else { 
     25    $referer = $_SERVER['HTTP_REFERER']; 
     26  } 
     27 
     28  $cookieVal = $_COOKIE[$cookie_name]; 
     29  if($cookieVal==0) { 
     30    $apacheHeader = apache_response_headers(); 
     31    $explodeResult1 = explode(';',$apacheHeader['Set-Cookie']); 
     32    $explodeResult2 = explode('=',$explodeResult1[0]); 
     33    $cookieVal = $explodeResult2[1]; 
     34  } 
     35 
     36  $log_entry = "\"".$cookieVal."\" \"".gmdate('Y-m-d H:i:s')."\" \"".$_SERVER['REQUEST_URI']."\" \"".$referer."\" \"".$_SERVER['HTTP_USER_AGENT']."\" \"".$postkeys."\"\r\n"; 
     37  $fp=fopen( $log_dir . $log_name, 'a' ); 
     38  fputs($fp, $log_entry); 
     39  fclose($fp); 
     40?> 
     41 
     42}}}