附上 CONFIG内代码 求大神们看下哪里错了<?php
header ( "Content-Type: text/html;charset=UTF-8" );
include_once 'func.php';
session_start ();
$LOG_RESULT = [
0 => "失败",
1 => "成功",
2 => "异常"
];
$SIZE_RANGE = [
10,
20,
30,
40,
50
];
define ( 'DB_HOST', 'localhost' );
define ( 'DB_PORT', 3306 );
define ( 'DB_NAME', 'log' );
define ( 'DB_USERNAME', 'root' );
define ( 'DB_PWD', ww021300 );
define ( 'LOG_DATA_TABLE', 'logdata' );
define ( 'LOG_OPT_TABLE', 'logopt' );
define ( 'LOG_MODULE_TABLE', 'logmodule' );
define ( 'DB_KEYWORDS_TABLE', 'keywords' );
define ( 'LOG_USERNAME', 'log' );
define ( 'LOG_PASSWORD', 'log' );
define ( 'USERNAME', 'username' );
define ( 'LOGIN_TAG', 'isLogLogin' );
define ( 'PAGE_RANGE', 10 );
define ( 'LOGINURL', 'login.php' );
define ( 'OPT_AUTO', '0' );
class RESULTYPE {
const SUCCESS = 1;
const FAIL = 0;
const ERROR = 2;
}
date_default_timezone_set ( 'Asia/Shanghai' );?>
header ( "Content-Type: text/html;charset=UTF-8" );
include_once 'func.php';
session_start ();
$LOG_RESULT = [
0 => "失败",
1 => "成功",
2 => "异常"
];
$SIZE_RANGE = [
10,
20,
30,
40,
50
];
define ( 'DB_HOST', 'localhost' );
define ( 'DB_PORT', 3306 );
define ( 'DB_NAME', 'log' );
define ( 'DB_USERNAME', 'root' );
define ( 'DB_PWD', ww021300 );
define ( 'LOG_DATA_TABLE', 'logdata' );
define ( 'LOG_OPT_TABLE', 'logopt' );
define ( 'LOG_MODULE_TABLE', 'logmodule' );
define ( 'DB_KEYWORDS_TABLE', 'keywords' );
define ( 'LOG_USERNAME', 'log' );
define ( 'LOG_PASSWORD', 'log' );
define ( 'USERNAME', 'username' );
define ( 'LOGIN_TAG', 'isLogLogin' );
define ( 'PAGE_RANGE', 10 );
define ( 'LOGINURL', 'login.php' );
define ( 'OPT_AUTO', '0' );
class RESULTYPE {
const SUCCESS = 1;
const FAIL = 0;
const ERROR = 2;
}
date_default_timezone_set ( 'Asia/Shanghai' );?>
现在我用5.6 的版本 提示这个错误
PHP Strict Standards: Declaration of LOG::error() should be compatible with DB::error() in D:\WWW\src\security\func.php on line 159
PHP Strict Standards: Declaration of LOG::count() should be compatible with DB::count($sql) in D:\WWW\src\security\func.php on line 159
程序我确定没问题
但是 LOG::error() 方法的声明与 DB::error() 方法的声明不一致
现在我用5.6 的版本 提示这个错误
PHP Strict Standards: Declaration of LOG::error() should be compatible with DB::error() in D:\WWW\src\security\func.php on line 159
PHP Strict Standards: Declaration of LOG::count() should be compatible with DB::count($sql) in D:\WWW\src\security\func.php on line 159
程序我确定没问题现在报错的是\func.php
我贴下这个文件的代码
<?php
class DB {
private $con;
function DB() {
$this->conn ( DB_HOST, DB_USERNAME, DB_PWD, DB_NAME, DB_PORT );
}
function conn($host = 'localhost', $user, $pwd, $dbname) {
$this->con = mysql_connect ( $host, $user, $pwd ) or $this->error ();
mysql_select_db ( $dbname );
}
function close() {
if ($this->con) {
@mysql_close ( $this->con );
}
}
function execute($sql) {
$res = mysql_query ( $sql, $this->con );
return mysql_affected_rows ( $this->con );
}
function error() {
die ( sprintf ( "[%d]: %s", mysql_errno (), mysql_error () ) );
// header ( 'Location: error.php' );
exit ();
}
function query($sql) {
$res = mysql_query ( $sql, $this->con ) or $this->error ();
$arr = [ ];
while ( ($row = mysql_fetch_array ( $res, MYSQL_ASSOC )) !== FALSE ) {
$arr [] = $row;
}
mysql_free_result ( $res );
return $arr;
}
function count($sql) {
$res = mysql_query ( $sql, $this->con ) or $this->error ();
if (($row = mysql_fetch_row ( $res )) !== FALSE) {
mysql_free_result ( $res );
return $row [0];
}
return FALSE;
}
}
class LOGEntity {
public $ip;
public $username;
public $time;
public $opt;
public $result;
public $msg;
function LOGEntity($result, $msg = '') {
$this->ip = $_SERVER ['REMOTE_ADDR'];
$this->username = mysql_real_escape_string ( $_SESSION [USERNAME] );
$this->time = date ( 'Y-m-d H:i:s' );
$this->result = mysql_real_escape_string ( $result );
$this->msg = mysql_real_escape_string ( $msg );
$this->opt = $this->mapper ( $_SERVER ['REQUEST_URI'] );
}
function mapper($url) {
global $db;
$sql = sprintf ( "select idx from " . LOG_OPT_TABLE . " where url='%s'", $url );
$id = $db->count ( $sql );
return $id;
}
}
class LOG extends DB {
private $db;
private $count;
private $username;
function LOG($db) {
$this->db = $db;
}
function save($username, $opt, $result, $msg) {
$fmt = "insert into %s(`username`,`ip`,`time`,`opt`,`result`,`msg`)VALUES('%s','%s','%s','%s','%s','%s')";
$time = date ( 'Y-m-d H:i:s' );
$ip = $_SERVER ['REMOTE_ADDR'];
$msg = mysql_real_escape_string ( $msg );
if (OPT_AUTO == $opt) {
$opt = $this->mapper ( $_SERVER ['REQUEST_URI'] );
}
$opt = mysql_real_escape_string ( $opt );
$username = mysql_real_escape_string ( $username );
$sql = sprintf ( $fmt, LOG_DATA_TABLE, $username, $ip, $time, $opt, $result, $msg );
}
function success($opt, $msg = '') {
$this->save ( $_SESSION [USERNAME], $opt, RESULTYPE::SUCCESS, $msg );
}
function fail($opt, $msg) {
$this->save ( $_SESSION [USERNAME], $opt, RESULTYPE::FAIL, $msg );
}
function error($opt, $msg) {
$this->save ( $_SESSION [USERNAME], $opt, RESULTYPE::ERROR, $msg );
}
function logSuccess($username, $opt, $msg) {
$this->save ( $username, $opt, RESULTYPE::SUCCESS, $msg );
}
function logFail($username, $opt, $msg) {
$this->save ( $username, $opt, RESULTYPE::FAIL, $msg );
}
function logError($username, $opt, $msg) {
$this->save ( $username, $opt, RESULTYPE::ERROR, $msg );
}
function load($startTime, $endTime, $username, $ip, $opt, $result, $page = 1, $size = 10) {
$sql = sprintf ( 'select COUNT(1) FROM %s WHERE 1=1 ', LOG_DATA_TABLE );
if (! is_null ( $username )) {
$sql .= sprintf ( " AND INSTR(`username`,'%s')", mysql_real_escape_string ( $username ) );
}
if (! is_null ( $ip )) {
$sql .= sprintf ( " AND INSTR(`ip`,'%s')", mysql_real_escape_string ( $ip ) );
}
$common = '';
if (! is_null ( $opt )) {
$common .= ' AND `opt`= ' . (( int ) $opt);
}
if (! is_null ( $result )) {
$common .= ' AND `result`= ' . (( int ) $result);
}
if (! is_null ( $startTime ) && ! is_null ( $endTime )) {
$common .= sprintf ( " AND `time` Between '%s 00:00:00' AND '%s 23:59:59'", mysql_real_escape_string ( $startTime ), mysql_real_escape_string ( $endTime ) );
} else if (! is_null ( $startTime )) {
$common .= sprintf ( " AND `time` >'%s 00:00:00'", mysql_real_escape_string ( $startTime ) );
}
$sql .= $common;
$this->count = $this->db->count ( $sql );
$start = ($page - 1) * $size;
if ($start < 0) {
$start = 0;
}
if ($this->count == 0 || $start > $this->count) {
return NULL;
}
$_size = $size;
if ($this->count - $start <= $size) {
$_size = $this->count - $start;
}
$sql = sprintf ( 'select l.`time`, l.idx,l.username,l.`ip`,m.`name` as module,o.`name` as opt,l.result,l.`msg` FROM %s as l LEFT JOIN %s as o ON l.`opt`=o.idx LEFT JOIN %s as m ON `o`.module=`m`.idx WHERE 1=1 ', LOG_DATA_TABLE, LOG_OPT_TABLE, LOG_MODULE_TABLE );
if (! is_null ( $username )) {
$sql .= sprintf ( " AND INSTR(`username`,'%s')", mysql_real_escape_string ( $username ) );
}
if (! is_null ( $ip )) {
$sql .= sprintf ( " AND INSTR(`ip`,'%s')", mysql_real_escape_string ( $ip ) );
}
$sql .= $common;
$sql .= " limit $start,$_size";
return $this->db->query ( $sql );
}
function count() {
return $this->count;
}
function loadModules() {
$sql = sprintf ( 'select * from %s order by `name`', LOG_MODULE_TABLE );
return $this->db->query ( $sql );
}
function loadOpts() {
$sql = sprintf ( 'select idx,module,`name` from %s order by `name`', LOG_OPT_TABLE );
return $this->db->query ( $sql );
}
}
class KeywordFilter {
private $db;
private $count;
private $keylist;
private $log;
function KeywordFilter($db, $log) {
$this->db = $db;
$this->log = $log;
}
function init() {
$sql = sprintf ( "SELECT word FROM %s order by `word`", DB_KEYWORDS_TABLE );
$res = $this->db->query ( $sql );
$this->keylist = [ ];
foreach ( $res as $item ) {
$this->keylist [] = $item ['word'];
}
}
function filter($input) {
$str = $input;
$isFilter = false;
if (is_null ( $this->keylist )) {
$this->init ();
}
foreach ( $this->keylist as $key ) {
if (strpos ( $str, $key ) !== FALSE) {
$isFilter = true;
$str = str_replace ( $str, $key, str_repeat ( '*', strlen ( $key ) ) );
}
}
if ($isFilter) {
$this->log->error ( '妫€娴嬪埌闈炴硶鍏抽敭瀛? );
}
return $input;
}
function load($content, $page, $size) {
$sql = sprintf ( "select count(1) from %s ", DB_KEYWORDS_TABLE );
if (! is_null ( $content )) {
$sql .= sprintf ( " where instr(`word`,'%s')", mysql_real_escape_string ( $content ) );
}
$this->count = $this->db->count ( $sql );
$start = ($page - 1) * $size;
if ($this->count == 0 || $start > $this->count) {
return NULL;
}
$_size = $size;
if ($this->count - $start <= $size) {
$_size = $this->count - $start;
}
$sql = 'select * from ' . DB_KEYWORDS_TABLE;
if (! is_null ( $content )) {
$sql .= sprintf ( " where instr(`word`,'%s')", mysql_real_escape_string ( $content ) );
}
$sql .= sprintf ( " LIMIT %d,%d", $start, $size );
return $this->db->query ( $sql );
}
function count() {
return $this->count;
}
function save($word) {
$sql = sprintf ( "insert into %s(`word`,`time`)VALUES('%s','%s')", DB_KEYWORDS_TABLE, mysql_real_escape_string ( $word ), date ( 'Y-m-d H:i:s' ) );
$res = $this->db->execute ( $sql );
return $res == 1;
}
function delete($id) {
$sql = sprintf ( "delete from %s where idx='%d'", DB_KEYWORDS_TABLE, $id );
$res = $this->db->execute ( $sql );
return $res == 1;
}
function edit($id, $word) {
$sql = sprintf ( "update %s set `word`='%s',`time`='%s' where idx='%d'", DB_KEYWORDS_TABLE, mysql_real_escape_string ( $word ), date ( 'Y-m-d H:i:s' ), $id );
$res = $this->db->execute ( $sql );
return $res == 1;
}
}
function calPage($cur, $total, $pageSize, $pageNum) {
$cur = $cur < 1 ? 1 : $cur;
$maxPage = ceil ( $total / $pageSize );
$cur = $cur > $maxPage ? $maxPage : $cur;
$start = $cur - floor ( $pageNum / 2 );
$start = $start < 1 ? 1 : $start;
$end = $cur + floor ( $pageNum / 2 );
$end = $end > $maxPage ? $maxPage : $end;
$range = $end - $start + 1;
if ($range < $pageNum && $start > 1) {
$start = $start - ($pageNum - $range);
$start = $start < 1 ? 1 : $start;
$range = $end - $start + 1;
}
if ($range < $pageNum && $end < $maxPage) {
$end = $end + ($pageNum - $range);
$end = $end > $maxPage ? $maxPage : $end;
}
return [
$start,
$end
];
}
function checkLogin() {
if (! isset ( $_SESSION [LOGIN_TAG] ) || $_SESSION [LOGIN_TAG] != LOGIN_TAG) {
echo sprintf ( "<script>alert('璇峰厛鐧诲綍!');location.href='login.php';</script>" );
exit ();
}
}
?>
function error() {
}
}
class LOG extends DB {
function error($opt, $msg) {
}
}
DB::error 没有参数
LOG::error 有两个参数
这就问题所在,所以错误信息说:should be compatible(应该是兼容的)
class DB {
function error() {
}
}
class LOG extends DB {
function error($opt='', $msg='') {
}
}
$this->save ( $_SESSION [USERNAME], $opt, RESULTYPE::ERROR, $msg );
}