0
我有一個註釋框表單並且正在運行,而我剛注意到當我使用'
時,它在它前面創建了一個\
。例如,如果我寫了「如何」,它會顯示爲數據庫中發佈的內容以及顯示在頁面上的「如何」。當我顯示「body」文本時,我使用stripslashes
函數,我認爲這是應該去掉斜線。儘管使用反斜線,斜線顯示在顯示的文本中
我的服務器運行PHP版本5.3.6,如果有幫助。
我使用這段代碼從註釋框的正文文本張貼到我的數據庫:
$body = mysql_prep($_POST['body']);
它使用的功能是這樣的:
function mysql_prep($string) {
global $connection;
$escaped_string = mysqli_real_escape_string($connection, $string);
return $escaped_string;
}
方請注意:你不需要回答這個問題,但這是我用來讓文本用戶免受黑客,壞人和其他所有人傷害的功能。我做得那麼好,還是讓我自己面對問題? (除了這個斜槓的問題,可能是因爲此功能)
這是我用來顯示文本代碼:
<div id="comments">
<?php while($comment_text = mysqli_fetch_assoc($display_comments)) { ?>
<div class="comment" style="margin-bottom: 2em;">
<div class="author">
<b><?php echo htmlentities($comment_text["author"]); ?>:</b>
</div>
<div class="meta-info" style="font-size: 0.8em;">
<?php echo datetime_to_text($comment_text["created"]); ?>
</div>
<div class="body">
<?php echo stripslashes($comment_text["body"], '<strong><em><p>'); ?>
</div>
</div>
<?php } ?>
<?php if(empty($display_comments)) { echo "No Comments."; } ?>
</div>
任何幫助或建議是超級感謝,謝謝!
我沒有看到'stripslashes()'。我只看到'strip_tags()'(它做了其他的事情)。 –
在準備MySQLi查詢時,您不需要'mysqli_real_escape_string()'函數。 –
哦當然,你的右@Gerald Schneider!我想我會把它拿出來,然後放入反斜槓?除非我正在搞這樣做...... – coolpup