Fix for Anonymous Track

  1. /**
  2.  * Implementation of hook_init().
  3.  */
  4. function anonymous_track_init(){
  5.         global $user;
  6.        
  7.         // Setup session id
  8.         $sessid = session_id();
  9.        
  10.         // Setup commons variables
  11.         $user_ip = $_SERVER['REMOTE_ADDR'];
  12.         $user_agent = $_SERVER['HTTP_USER_AGENT'];
  13.         $sess_id = session_id();
  14.         $url_curr = $_SERVER['HTTP_HOST'] . base_path() . drupal_get_path_alias($_GET['q']);
  15.         $url_referer = $_SERVER['HTTP_REFERER'];
  16.        
  17.         /*
  18.         // Display messages
  19.         drupal_set_message('Data: '.$date, 'status');
  20.         drupal_set_message('IP: '.$user_ip, 'status');
  21.         drupal_set_message('Browser: '.$user_agent, 'status');
  22.         drupal_set_message('URL: '.$url_curr, 'status');
  23.         drupal_set_message('Referer '.$url_referer, 'status');
  24.         drupal_set_message('SESSID: '.$sess_id, 'status');
  25.         */
  26.        
  27.         // If user is Anonymous
  28.         if($user->uid == 0){
  29.                 // Execute query
  30.                 db_query("INSERT INTO {user_stats} (sid, sessid, ip, agent, url, referer, date) VALUES (%d, '$sess_id', '$user_ip', '$user_agent', '$url_curr', '$url_referer', now())");
  31.         }
  32. }
  33.  
  34. /**
  35.  * Implementation of hook_form_alter().
  36.  */
  37. function anonymous_track_form_alter(&$form, &$form_state, $form_id) {
  38.         if ($form_id == 'webform_client_form_61') {
  39.                 $form['#submit'][] = 'anonymous_track_webform_submit';
  40.         }
  41. }
  42. function anonymous_track_webform_submit(&$form, &$form_state) {
  43.         drupal_set_message('Enviou!','status');
  44. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.