简体   繁体   English

添加了元标记UTF 8,但尚未声明HTML文档的字符编码仍在获取它

[英]Added Meta tag UTF 8 but the character encoding of the HTML document was not declared still getting it

I am getting error in console even I added UTF-8 即使添加了UTF-8,我在控制台中也出现错误

The character encoding of the HTML document was not declared. 未声明HTML文档的字符编码。 The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. 如果文档包含来自US-ASCII范围之外的字符,则在某些浏览器配置中,文档将呈现乱码。 The character encoding of the page must be declared in the document or in the transfer protocol. 页面的字符编码必须在文档或传输协议中声明。

I already added in HMTL head. 我已经添加了HMTL头。

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

If I delete below my PHP code from HTML then It's working properly 如果我从HTML删除我的PHP代码下方,则说明工作正常

Note: $GET['Key'] values comes from URL(domain.com/details?key=uYxnJrS3aLv0JbJFLnnmW4TRRpF6%2FYB0JD6LUhPYu0U%3D) 注意: $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();
     }
}

Below Is the function to change my ID encryption to decryption and vice and versa 以下是将我的ID加密更改为解密的功能,反之亦然

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 ) ) ), "\0");
    return( $qDecoded );
}

Connection.php 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);
}

After adding $conn->set_charset('utf8'); 添加$conn->set_charset('utf8'); in database connection file getting and also added ini_set('display_errors', 1); 在数据库连接文件中获取并还添加了ini_set('display_errors', 1); then I am getting error 那我就出错了

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

您应该写:

<meta charset="utf-8" />

Finally, I found my answer. 最后,我找到了答案。 What I did, I created a php.ini file in the public_html folder and added below code in it. 我所做的是,我在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;

but still, I was getting the issue. 但仍然,我遇到了问题。 I was using prepared statement then I added 我正在使用准备好的语句,然后添加了

$stmt->store_result();

before $stmt->bind_result() and this time it was working perfeclty. $stmt->bind_result() ,这次是正常运行。

If anyone getting the same issue then try this solution. 如果有人遇到相同问题,请尝试此解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM