MyBB Community Forums

Full Version: User IP Log plugin function iplog_exec() problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
function iplog_exec(), in file iplog.php @ line 72, only works if the login attempt succeeded; otherwise, $user['uid'] is empty, causing an SQL error upon Insert of the uid column data (i.e., '' ) into table iplogs.

Note that iplogs.uid is an Integer column; and besides, what good is logging the IP if you don't know what the uid (or who the user) is.

Proposed fix (which I've just tried successfully):
function iplog_exec()
{
  global $user, $db;
  // ***** Added if() condition to prevent SQL error after failed login
  if ( isset( $user['uid'] ) && !empty( $user['uid'] ) ) {
    $values = array(
      'uid'       => $db->escape_string( $user['uid'] ),
      'ipaddress' => $db->escape_string( get_ip() ),
      'dateline'  => $db->escape_string( time() )
    );
    $db->insert_query( 'iplogs', $values );
  }
}

Thanks.