table_common_failedip.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_common_failedip.php 33692 2013-08-02 10:26:20Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_failedip extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_failedip';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function get_ip_count($ip, $time) {
  19. return DB::result_first("SELECT SUM(`count`) FROM %t WHERE ip=%s AND lastupdate>%d", array($this->_table, $ip, $time));
  20. }
  21. public function insert_ip($ip) {
  22. if(DB::result_first("SELECT COUNT(*) FROM %t WHERE ip=%s AND lastupdate=%d", array($this->_table, $ip, TIMESTAMP))) {
  23. DB::query("UPDATE %t SET `count`=`count`+1 WHERE ip=%s AND lastupdate=%d", array($this->_table, $ip, TIMESTAMP));
  24. } else {
  25. DB::query("INSERT INTO %t VALUES (%s, %d, 1)", array($this->_table, $ip, TIMESTAMP));
  26. }
  27. DB::query("DELETE FROM %t WHERE lastupdate<%d", array($this->_table, TIMESTAMP - 3600));
  28. }
  29. }
  30. ?>