<?php
  /*
   * Usage monitoring script for PHP web applications.
   * Requires the apache modules mod_usertrack to provide
   * a cookie for user identification.
   */
  $log_dir = dirname( __FILE__)."/";
  $log_name = "usage.log";
  $cookie_name = "swe_informatik_uni-goettingen_de";

  $postkeys = "";

  while (list($key, $value) = each($_POST)) {
    $postkeys = $postkeys." ".$key;
  }
  if( $_SERVER['HTTP_REFERER']=='' ) {
    $referer = '-';
  } else {
    $referer = $_SERVER['HTTP_REFERER'];
  }

  $cookieVal = $_COOKIE[$cookie_name];
  if($cookieVal==0) {
    $apacheHeader = apache_response_headers();
    $explodeResult1 = explode(';',$apacheHeader['Set-Cookie']);
    $explodeResult2 = explode('=',$explodeResult1[0]);
    $cookieVal = $explodeResult2[1];
  }

  $log_entry = "\"".$cookieVal."\" \"".gmdate('Y-m-d H:i:s')."\" \"".$_SERVER['REQUEST_URI']."\" \"".$referer."\" \"".$_SERVER['HTTP_USER_AGENT']."\" \"".$postkeys."\"\r\n";
  $fp=fopen( $log_dir . $log_name, 'a' );
  fputs($fp, $log_entry);
  fclose($fp);
?>
