Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2008, 05:33 PM
enci enci is offline
 
Join Date: Feb 2008
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP Plugin Error

I am trying to place a php script on my board to track user information such as referer, query string, etc. I created a plugin and placed it in the parse_templates hook location. However, when I activate the plugin and test it, I see these errors in my error_log:

PHP Fatal error: Call to a member function query_read_slave() on a non-object in /path/to/board/includes/functions.php on line 2970

PHP Fatal error: Call to a member function shutdown_query() on a non-object in /path/to/board/showthread.php on line 490

PHP Fatal error: Call to a member function unlock_tables() on a non-object in /path/to/board/includes/functions.php on line 4998

I am pretty sure my php script works because I copied it directly from a working script.

Thanks.
Reply With Quote
  #2  
Old 03-19-2008, 05:38 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please post the plugin code.
Reply With Quote
  #3  
Old 03-19-2008, 05:51 PM
enci enci is offline
 
Join Date: Feb 2008
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
$script_parts = preg_split("/\//", preg_replace("/^\//", "", $SCRIPT_NAME));
$thispage = array_pop($script_parts);
$thispage = preg_replace("/.php/", "", $thispage);
$section = "forum";
$campaign = $_SERVER['QUERY_STRING'];

#if page is index page, we want to log page category, so array_pop "index" to get category
#example, if page is /Insurance/index.php, we'll array_pop so name becomes Insurance instead of index
if ($thispage == "index") {
   $thispage = array_pop($script_parts);
   if ($thispage == "") {
      $thispage = "Home";
   }
   $thispage = $thispage."_Index";
}

$name = $thispage;

function email_error($reason) {
   $to = "email@test.com";
   $from = "From: db_error@test.com\r\n";
   $subject = "DB Error in Logs DB";

   $body = "There was an error in the logging function of the forum.  ".$reason;

   mail($to, $subject, $body, "$from");
} #end function email_error

function parse_se ($url) {
   if (stripos($url,"translate.google.com") == TRUE) {
      $engine = "Google Translate BETA";
   } elseif (stripos($url,"google.com") == TRUE) {
      $engine = "Google US";
   } elseif (stripos($url,"google.ca") == TRUE) {
      $engine = "Google Canada";
   } elseif (stripos($url,"google.co.uk") == TRUE) {
      $engine = "Google UK";
   } elseif (stripos($url,"google.com.nz") == TRUE) {
      $engine = "Google New Zealand";
   } elseif (stripos($url,"google.com.mx") == TRUE) {
      $engine = "Google Mexico";
   } elseif (stripos($url,"google.com.do") == TRUE) {
      $engine = "Google DR";
   } elseif (stripos($url,"google.co.at") == TRUE || stripos($url,"google.at") == TRUE) {
      $engine = "Google Germany";
   } elseif (stripos($url,"google.co.it") == TRUE || stripos($url,"google.it") == TRUE) {
      $engine = "Google Italy";
   } elseif (stripos($url,"google.com.tr") == TRUE) {
      $engine = "Google Turkey";
   } elseif (stripos($url,"google.ie") == TRUE) {
      $engine = "Google Ireland";
   } elseif (stripos($url,"dmoz.org") == TRUE) {
      $engine = "DMOZ";
   } elseif (stripos($url,"uk.ask.com") == TRUE) {
      $engine = "Ask UK";
   } elseif (stripos($url,"www.ask.com") == TRUE) {
      $engine = "Ask US";
   } elseif (stripos($url,"search.msn.com") == TRUE || stripos($url,"search.live.com") == TRUE) {
      $engine = "MSN US";
   } elseif (stripos($url,"search.msn.co.uk") == TRUE) {
      $engine = "MSN UK";
   } elseif (stripos($url,"search.msn.co.it") == TRUE) {
      $engine = "MSN Italy";
   } elseif (stripos($url,"netscape.com") == TRUE ) {
      $engine = "Netscape";
   } elseif (stripos($url,"aolsearch.aol.co.uk") == TRUE ) {
      $engine = "AOL UK";
   } elseif (stripos($url,"search.aol.com.au") == TRUE ) {
      $engine = "AOL AU";
   } elseif (stripos($url,"aolsearcht") == TRUE ) {
      $engine = "AOL";
   } elseif (stripos($url,"mail.yahoo.com") == TRUE ) {
      $engine = "Yahoo! Mail";
   } elseif (stripos($url,"images.search.yahoo.com") == TRUE ) {
      $engine = "Yahoo! Images";
   } elseif (stripos($url,"uk.search.yahoo.com") == TRUE ) {
      $engine = "Yahoo! UK";
   } elseif (stripos($url,"finance.groups.yahoo.com") == TRUE ) {
      $engine = "Yahoo! Finance";
   } elseif (stripos($url,"search.yahoo.com") == TRUE || stripos($url,"my.yahoo.com") == TRUE ) {
      $engine = "Yahoo!";
   } elseif (stripos($url,"aolsearch.aol.ca") == TRUE  || stripos($url,"search.aol.ca") == TRUE ) {
      $engine = "AOL CA";
   } elseif (stripos($url,"aolsearch.aol.com") == TRUE  || stripos($url,"search.aol.com") == TRUE ) {
      $engine = "AOL";
   } else { 
      # create a new string called $strip_http which contains the url minus http://
      $strip_http = substr($url,7);
      # find the position of the first / so we can locate the search engine or referer domain
      $slash_pos = stripos($strip_http,"/");
      # find search engine or referer domain
      $engine = substr($strip_http,0,$slash_pos);
   }  
      
   return addslashes($engine);
      
}# end function parse_se
      
function parse_terms ($url) {
      
   # decoded URL to remove encoding characters
   $url = urldecode($url);
   
   # if referer url is internal, no query terms needed, but determine campaign tracking and put into referer
   
  if (stripos($url,"ahoo") == TRUE ) {
      if (stripos($url,"&p=") == TRUE) {
         $pos = stripos($url,"&p=");
         $query_url = substr($url,$pos+3);
         $end_pos = stripos($query_url,"&");
         if ($end_pos == null) {
            $terms = str_replace("+"," ",substr($query_url,0));
         } else {
            $terms = str_replace("+"," ",substr($query_url,0,$end_pos));
         }
      } elseif (stripos($url,"?p=") == TRUE) {
         $pos = stripos($url,"?p=");
         $query_url = substr($url,$pos+3);
         $end_pos = stripos($query_url,"&");
         if ($end_pos == null) {
            $terms = str_replace("+"," ",substr($query_url,0));
         } else {
            $terms = str_replace("+"," ",substr($query_url,0,$end_pos));
         }
      } else {
         $terms = "";
      }
   } elseif (stripos($url,"?encquery=") == TRUE) {
         $pos = stripos($url,"?encquery=");
         $query_url = substr($url,$pos+10);
         $end_pos = stripos($query_url,"&");
         if ($end_pos == null) {
            $encoded_query = str_replace("+"," ",substr($query_url,0));
         } else {
            $encoded_query = str_replace("+"," ",substr($query_url,0,$end_pos));
         }
         $FU_AOL = implode( "", file( "http://search.aol.com/aolcom/search?encquery=$encoded_query" ));
         preg_match( '/<title>[^>]*"([^"]+)"<\/title>/', $FU_AOL, $decoded_query );
         $terms = $decoded_query[1];
   } else {
      # finds the beginning position of the query terms
      if (stripos($url,"&q=") == TRUE) {
         $pos = stripos($url,"&q=");
         $query_url = substr($url,$pos+3);
      } elseif (stripos($url,"?q=") == TRUE) {
         $pos = stripos($url,"?q=");
         $query_url = substr($url,$pos+3);
      } elseif (stripos($url,"query=") == TRUE) {
         $pos = stripos($url,"query=");
         $query_url = substr($url,$pos+6);
      } elseif (stripos($url,"?s=") == TRUE) {
         $pos = stripos($url,"?s=");
         $query_url = substr($url,$pos+3);
      } elseif (stripos($url,"&s=") == TRUE) {
         $pos = stripos($url,"&s=");
         $query_url = substr($url,$pos+3);
      }

      $end_pos = stripos($query_url,"&");

      # if pos is null, that means there are no query terms
      if ($pos == null) {
         $terms = "";
         return addslashes($terms);
      }

      if ($end_pos == null) {
         $terms = str_replace("+"," ",substr($query_url,0));
      } else {
         $terms = str_replace("+"," ",substr($query_url,0,$end_pos));
      }
   }
   return addslashes($terms);

}

# ********log referer info in mysql database table "logs"************

# won't log for internal ip addresses, or any ip addresses you put here
if (1==1) {
         
   require "/pwfile";
         
   $username = $usern;
   $password = $passw;
   $database = $datab;
            
   #connect to mysql
   $link = @mysql_connect('localhost',$username,$password);
         
   if (!$link) {
      email_error('Could not login to mysql.'.mysql_error());
   }  
      
   # connect to database in mysql
   $db_connect = @mysql_select_db($database);
      
   if (!$db_connect) {
           email_error("Could not establish connection with database.".mysql_error());
   }  
         
   # data to enter into ins_referer logs table; $name is set up above
   $referer = $_SERVER["HTTP_REFERER"];
   $ref_date = date('m/d/Y H:i:s');
   $browser = "";
   if (isset($_SERVER['HTTP_USER_AGENT'])) { 
      $user_agent = get_browser(null,true);
      $browser = $user_agent['browser'];
   }  

   if($referer == "") {
     $referer = "no_referer";
   }  
      
   $referer = addslashes($referer);
   $browser = addslashes($browser);
      
   $searchengine = parse_se($referer);
   $queryterms = parse_terms($referer);
         
   # this will track any campaigns we run, such as links from newsletters, and any others where there is no URL referer, such as browser refresh
   if ((stripos($campaign,"ccn=") !== FALSE)) {
      $referer = substr($campaign,4);
   }
   
   # INSERT statements

   $query = "INSERT INTO forum_table (name, referer, ref_date, searchengine, query, browser) VALUES ('$name','$referer','$ref_date','$searchengine','$queryterms','$browser')";
   $result = @mysql_query($query);

   if (!$result) {
           email_error("Could not insert into $section table.  ".mysql_error());
   }

   @mysql_close();

} #end if internal ip address
# ***********end log  info*****************
Reply With Quote
  #4  
Old 03-19-2008, 06:43 PM
King Kovifor's Avatar
King Kovifor King Kovifor is offline
 
Join Date: Nov 2004
Location: PA
Posts: 3,872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your plugin may be overwriting vBulletin classes. Trying renaming some of your variables by looking into the files referenced by the error message on that specific line. Then modify yours accordingly. This may solve your problem.

Some of the best vBulletin coding practices involves using the $vbulletin->db for all your database interactions. But I believe that
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:45 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01571 seconds
  • Memory Usage 2,217KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete