PHP Warning: mysqli_set_charset() expects parameter 1 to be mysqli

  Kiến thức lập trình

I record this error(s) every time a bot try to brute force in the website (and the attacks are relentless..):

First, the bot(s) are overwhelming the connection to the database and the result is:

PHP Warning: mysqli_connect(): (HY000/1203): User xxxxxxxx already has more than ‘max_user_connections’ active connections in /home/namehost/public_html/config.php on line 7

Than another error plague the connection..

PHP Warning: mysqli_set_charset() expects parameter 1 to be mysqli, bool given in /home/namehost/public_html/config.php on line 14

The error file ‘balloons’ from a mere 80b to over 400Mb in less than 23-27 seconds with only these two messages (above). Needless to say the entire website returns a 503 error (resources maxed out, almost instantly..)

The entire script (website) is less than 30Mb (and that include the media files)
This is the entire config.php file (creds masked for privacy):

<?php
$host     = "xxxxxxxx";
$user     = "xxxxxxxx";
$password = "xxxxxxxx";
$database = "xxxxxxxx";

$mysqli = mysqli_connect($host, $user, $password, $database);

// Checking Connection
if (mysqli_connect_errno()) {
    echo "Failed to connect with MySQL: " . mysqli_connect_error();
}

mysqli_set_charset($mysqli, "utf8mb4");

if(!session_id()){
    @session_start([
        'cookie_lifetime' => 86400,
    ]);
}
error_reporting(E_ERROR);
?>

Right now the website is behind strict rules – security-wise -, enforced by CDNs but the error still replicate (at a lower pace though..)

Is there a particular setting in the config that can address to overcome this error(s)?
Thank you.

New contributor

Sin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT