baseUrl(); $ip = request()->ip(); $key = md5($url . ':' . $ip); } $hasRedis = config('redis'); if ($hasRedis) { $redis = (new \addons\shopro\library\Redis())->getRedis(); if ($redis->exists($key)) { throw new \addons\shopro\exception\Exception('请不要重复提交'); } $redis->setex($key, $expire, time()); // 缓存 五秒 } else { if (cache('?' . $key)) { throw new \addons\shopro\exception\Exception('请不要重复提交'); } cache($key, time(), $expire); } } } /** * 过滤掉字符串中的 sql 关键字 */ if (!function_exists('filter_sql')) { function filter_sql($str) { $str = strtolower($str); // 转小写 $str = str_replace("and", "", $str); $str = str_replace("execute", "", $str); $str = str_replace("update", "", $str); $str = str_replace("count", "", $str); $str = str_replace("chr", "", $str); $str = str_replace("mid", "", $str); $str = str_replace("master", "", $str); $str = str_replace("truncate", "", $str); $str = str_replace("char", "", $str); $str = str_replace("declare", "", $str); $str = str_replace("select", "", $str); $str = str_replace("create", "", $str); $str = str_replace("delete", "", $str); $str = str_replace("insert", "", $str); $str = str_replace("union", "", $str); $str = str_replace("alter", "", $str); $str = str_replace("into", "", $str); $str = str_replace("'", "", $str); $str = str_replace("or", "", $str); $str = str_replace("=", "", $str); return $str; } } /** * 删除 sql mode 指定模式,或者直接关闭 sql mode */ if (!function_exists('closeStrict')) { function closeStrict($modes = []) { $modes = array_filter(is_array($modes) ? $modes : [$modes]); $result = \think\Db::query("SELECT @@session.sql_mode"); $newModes = $oldModes = explode(',', ($result[0]['@@session.sql_mode'] ?? '')); if ($modes) { foreach ($modes as $mode) { $delkey = array_search($mode, $newModes); if ($delkey !== false) { unset($newModes[$delkey]); } } $newModes = join(',', array_values(array_filter($newModes))); } else { $newModes = ''; } \think\Db::execute("set session sql_mode='" . $newModes . "'"); return $oldModes; } } /** * 重新打开被关闭的 sql mode */ if (!function_exists('recoverStrict')) { function recoverStrict($modes = [], $append = false) { if ($append) { $result = \think\Db::query("SELECT @@session.sql_mode"); $oldModes = explode(',', ($result[0]['@@session.sql_mode'] ?? '')); $modes = array_values(array_filter(array_unique(array_merge($oldModes, $modes)))); } \think\Db::execute("set session sql_mode='" . join(',', $modes) . "'"); } }