Skip to content

Commit

Permalink
兼容 PHP 8.x 的更改
Browse files Browse the repository at this point in the history
  • Loading branch information
guguan123 committed Oct 3, 2024
1 parent 18ba4cd commit 6671ce2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 46 deletions.
74 changes: 33 additions & 41 deletions sys/inc/db_connect.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,49 @@
<?php
// 数据库服务器上的授权
$db = @mysqli_connect($set['mysql_host'], $set['mysql_user'], $set['mysql_pass'],$set['mysql_db_name']);
if (mysqli_connect_errno($db))
{
exit("连接 MySQL 失败: " . mysqli_connect_error());
if (mysqli_connect_errno()) /* 原判断语句为“(mysqli_connect_errno($db))”不知道为什么原作者要传递参数,但是在 PHP8.x 无法运行了 */ {
exit("连接 MySQL 失败: " . mysqli_connect_error());
}
$query_number = 0;
$tpassed = 0;
function dbresult($result, $row, $field = 0)
{
$numrows = mysqli_num_rows($result);
if ($numrows && $row <= ($numrows - 1) && $row >= 0) {
mysqli_data_seek($result, $row);
$resrow = (is_numeric($field)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result);
if (isset($resrow[$field])) {
return $resrow[$field];
}
}
}
function dbquery($query)
{
global $db;
return mysqli_query($db, $query);
}
function dbrows($result)
{
global $db;
return mysqli_num_rows($result);
}
function dbarray($result)
{
global $db;
return mysqli_fetch_array($result);
}
function dbassoc($result)
{
global $db;
return mysqli_fetch_assoc($result);
}
function dbinsertid(){
global $db;
return mysqli_insert_id($db);
function dbresult($result, $row, $field = 0) {
$numrows = mysqli_num_rows($result);
if ($numrows && $row <= ($numrows - 1) && $row >= 0) {
mysqli_data_seek($result, $row);
$resrow = (is_numeric($field)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result);
if (isset($resrow[$field])) {
return $resrow[$field];
}
}
}
function dbquery($query) {
global $db;
return mysqli_query($db, $query);
}
function dbrows($result) {
global $db;
return mysqli_num_rows($result);
}
function dbarray($result) {
global $db;
return mysqli_fetch_array($result);
}
function dbassoc($result) {
global $db;
return mysqli_fetch_assoc($result);
}
function dbinsertid() {
global $db;
return mysqli_insert_id($db);
}
dbquery('set charset utf8mb4',$db);
dbquery('SET names utf8mb4',$db);
dbquery('set character_set_client="utf8mb4"',$db);
dbquery('set character_set_connection="utf8mb4"',$db);

function db_optimize()
{
function db_optimize() {
$tab = dbquery('SHOW TABLES');
while ($tables = dbarray($tab))
{
while ($tables = dbarray($tab)) {
dbquery("OPTIMIZE TABLE `$tables[0]`");
}
}
10 changes: 5 additions & 5 deletions sys/inc/fnc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// 函数别名
// 剪切所有不可读字符
function my_esc($text, $br = NULL) {
if ($br != NULL) {
for ($i = 0; $i <= 31; $i++) $text = str_replace(chr($i), NULL, $text);
if ($br != '') {
for ($i = 0; $i <= 31; $i++) $text = str_replace(chr($i), '', $text);
} else {
for ($i = 0; $i < 10; $i++) $text = str_replace(chr($i), NULL, $text);
for ($i = 11; $i < 20; $i++) $text = str_replace(chr($i), NULL, $text);
for ($i = 21; $i <= 31; $i++) $text = str_replace(chr($i), NULL, $text);
for ($i = 0; $i < 10; $i++) $text = str_replace(chr($i), '', $text);
for ($i = 11; $i < 20; $i++) $text = str_replace(chr($i), '', $text);
for ($i = 21; $i <= 31; $i++) $text = str_replace(chr($i), '', $text);
}
return $text;
}
Expand Down
2 changes: 2 additions & 0 deletions sys/inc/ipua.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function loadCloudflareIps($filePath) {
case 'auto':
default:
// 自动模式,尝试从多个标头获取
$ip2 = [];
$ipa = [];
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']!='127.0.0.1' && preg_match("#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#",$_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip2['xff'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ipa[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
Expand Down

0 comments on commit 6671ce2

Please sign in to comment.