2017-09-16 47 views
2

我收到錯誤控制檯連我加入UTF-8加元標記UTF-8,但HTML文檔的字符編碼未聲明仍然得到它

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

我已經在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密碼改到解密的功能和反之亦然

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

$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) 
+0

是你的數據庫使用utf8的字符集? – Ramadhan

+0

我不知道。我應該在哪裏設置它? –

+0

phpmyadmin,並看看你的數據庫列表。在那裏有關於字符集的信息 – Ramadhan

回答

0

最後,我找到了我的答案。 我做了什麼,我在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()之前,這一次是工作perfeclty。

如果有人遇到同樣的問題,請嘗試此解決方案。

0

你應該寫後:

<meta charset="utf-8" /> 
+0

我試過但也是同樣的問題 –

+0

您需要檢查DataBase字符集;當你創建與數據庫的連接時你可以設置默認的字符集,例如:'$ conn-> set_charset('utf8')' –

+0

在數據庫中添加上面的字符集後,我得到了一些不同的錯誤。致命錯誤:允許的內存大小爲134217728字節耗盡(試圖分配4294967296字節) –

相關問題