添加了Meta Tag UTF 8,但尚未宣布HTML文档的字符编码仍在获取



我在控制台中遇到错误,即使我添加了UTF-8

未声明HTML文档的字符编码。如果文档包含来自US-ASCII范围外的字符,则该文档将在某些浏览器配置中使用乱码的文本渲染。页面的字符编码必须在文档或传输协议中声明。

我已经在HMTL头中添加。

<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">

如果我从HTML中删除PHP代码以下,则它的工作正常

注意:$GET['Key']值来自URL(domain.com/details?key=uYxnJrS3aLv0JbJFLnnmW4TRRpF6%2FYB0JD6LUhPYu0U%3D)

if ($conn->real_escape_string($_GET['key'])){
     $p_id=$conn->real_escape_string($_GET['key']);
     $decrypted_p_id = decryptIt($p_id);
     /*display single products*/
     $sql_single_products="SELECT p_images, p_name, p_company, p_status FROM products WHERE p_id=?";
     if ($stmt = $conn->prepare($sql_single_products)) {
          $stmt->bind_param("i", $decrypted_p_id);
          $stmt->execute();
          $stmt->bind_result($p_images, $name,$company,$status);
          $stmt->fetch();
     }
}

以下是将我的ID加密更改为解密和VICE的函数,反之亦然

function encryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
    return( $qEncoded );
}
function decryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "");
    return( $qDecoded );
}

Connection.php

$servername = "localhost";
$username = "user";
$password = "Pass#@123";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

在数据库连接文件中添加$conn->set_charset('utf8');后 还添加了ini_set('display_errors', 1);,然后我会遇到错误

Allowed memory size of 268435456 bytes exhausted (tried to allocate 4294967296 bytes)

您应该写:

<meta charset="utf-8" />

最后,我找到了答案。我所做的,我在public_html文件夹中创建了一个php.ini文件,并在其中添加了下面的代码。

memory_limit = 512M // before it was 256M if you want to check the current limit then add  `php_info();` in your PHP file then run your file.and find memory_limit.
post_max_size = 32M;
upload_max_filesize = 32M;

但是,我还是遇到了问题。我正在使用准备好的语句,然后添加了

$stmt->store_result();

$stmt->bind_result()之前,这一次它的工作正常。

如果有人遇到相同的问题,请尝试此解决方案。

最新更新