這是我的一種形式(PHP + MySQL,textarea替換爲TinyMCE)。它用段落,項目符號,標題和文本對齊(右,左,中心和正確)記錄描述。消毒輸入但輸出不如預期
一旦提交,如
<p style="text-align: justify;"><strong>Introduction</strong></p>
<p style="text-align: justify;">The death of the pixel leaves you with a flowing, magazine-quality canvas to design for. A canvas where curves are curves, not ugly pixel approximations of curves. A canvas that begins to blur the line between what we consider to be real and what we consider to be virtual.</p>
<p style="text-align: justify;">It wasn't too long ago that there was one set of rules for use of type on print and use of type on screen. Now that we have screens that are essentially print quality, we have to reevaluate these conventions.</p>
<p style="text-align: justify;">Web sites are transforming from boring fields of Arial to embrace the gamut of typographical possibilities offered by web fonts. Web fonts, combined with the style and layout options presented by the creative use of CSS and JavaScript offer a new world of typographic oppor</p>
<ol>
<li style="text-align: justify;">point 1</li>
<li style="text-align: justify;">point 2</li>
<li style="text-align: justify;">point 3</li>
</ol>
,我讀了你需要的是淨化進入數據庫的任何數據,以避免XSS並開始尋找解決方案出現的記錄。
我找到的解決方案是使用「htmlspecialchars()」(來源:Lynda.com - 創建安全的PHP網站)。
因此,本教程說,我們需要保存到數據庫之前清空我們的輸入,並使用類似(示例代碼)
<?php
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$category_description = $_POST['category_description'];
echo $category_description;
echo '<br><br>';
echo htmlspecialchars($category_description);
echo '<br><br>';
echo htmlentities($category_description);
echo '<br><br>';
echo strip_tags($category_description);
}
?>
避免XSS。
我知道它直到這裏。 htmlspecialchars()函數將一些預定義的字符轉換爲HTML實體,htmlentities()將字符轉換爲HTML實體,strip_tags()完全刪除任何標籤。
但結果使用htmlspecialchars(),ヶ輛(),並用strip_tags()後,輸出現在呈現爲
我相信這是安全的,但並不好看時取出的頭版從數據庫。
如何渲染已通過htmlspecialchars或htmlentities的輸入?
你嘗試過這種回聲<<< EOD $ category_description EOD;引用http://stackoverflow.com/questions/6924193/what-is-the-use-of-eod-in-php –
@PuyaSarmidani,我想我找到了一個解決方案。 –