久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <small id='EqEU6'></small><noframes id='EqEU6'>

      • <bdo id='EqEU6'></bdo><ul id='EqEU6'></ul>
      <tfoot id='EqEU6'></tfoot>
    1. <legend id='EqEU6'><style id='EqEU6'><dir id='EqEU6'><q id='EqEU6'></q></dir></style></legend>
      <i id='EqEU6'><tr id='EqEU6'><dt id='EqEU6'><q id='EqEU6'><span id='EqEU6'><b id='EqEU6'><form id='EqEU6'><ins id='EqEU6'></ins><ul id='EqEU6'></ul><sub id='EqEU6'></sub></form><legend id='EqEU6'></legend><bdo id='EqEU6'><pre id='EqEU6'><center id='EqEU6'></center></pre></bdo></b><th id='EqEU6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EqEU6'><tfoot id='EqEU6'></tfoot><dl id='EqEU6'><fieldset id='EqEU6'></fieldset></dl></div>

      1. 在 PDO 中使用 htmlspecialchars 函數準備和執行

        Using htmlspecialchars function with PDO prepare and execute(在 PDO 中使用 htmlspecialchars 函數準備和執行)
          <tbody id='HFQuG'></tbody>
        <tfoot id='HFQuG'></tfoot>

          • <bdo id='HFQuG'></bdo><ul id='HFQuG'></ul>

          • <legend id='HFQuG'><style id='HFQuG'><dir id='HFQuG'><q id='HFQuG'></q></dir></style></legend>

              1. <small id='HFQuG'></small><noframes id='HFQuG'>

                  <i id='HFQuG'><tr id='HFQuG'><dt id='HFQuG'><q id='HFQuG'><span id='HFQuG'><b id='HFQuG'><form id='HFQuG'><ins id='HFQuG'></ins><ul id='HFQuG'></ul><sub id='HFQuG'></sub></form><legend id='HFQuG'></legend><bdo id='HFQuG'><pre id='HFQuG'><center id='HFQuG'></center></pre></bdo></b><th id='HFQuG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HFQuG'><tfoot id='HFQuG'></tfoot><dl id='HFQuG'><fieldset id='HFQuG'></fieldset></dl></div>
                • 本文介紹了在 PDO 中使用 htmlspecialchars 函數準備和執行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  使用htmlspecialchars()函數的PHP PDO在表單驗證和數據庫查詢中將特殊字符轉換為HTML實體真的有必要嗎?

                  Is converting special characters to HTML entities in form validation and database query using PHP PDO using htmlspecialchars() function really necessary?

                  例如,我有一個或多或少具有簡單登錄系統的網站:

                  For example, I have a website with simple login system more or less like:

                  $username = (string) htmlspecialchars($_POST['user']);
                  $password = (string) htmlspecialchars($_POST['pass']);
                  
                  $query = $dbh->prepare("select id where username = ? and password = ?")
                  $query->execute($username, $password);
                  

                  請注意,除了所討論的函數之外,我還使用了類型轉換.那么,有必要嗎?或者我可以安全地使用 $username = $_POST['user']; ?

                  Note that I also use type casting besides the function in question.. So, is it necessary? Or I can safely use $username = $_POST['user']; ?

                  推薦答案

                  您的困惑很常見,因為書籍和互聯網(包括 php.net)上的信息和示例具有誤導性或歧義.在開發 Web 應用程序時,您可以學到的最重要的事情是 過濾輸入,轉義輸出.

                  Your confusion is quite common because information and examples in books and on the internet including php.net are misleading or ambiguous. The most important thing you can learn when developing web apps is filter input, escape output.

                  過濾輸入這意味著對于任何數據輸入,無論是由用戶在表單上提供的還是由其他來源的文件提供的,都要過濾掉任何不屬于的數據.一個例子是,如果您需要一個數字值,請過濾掉任何非數字字符.另一個例子是限制/確保數據的最大長度.但是,您不必為此發瘋.例如,如果您希望一行文本可以包含幾乎任何字符組合,那么嘗試提出過濾器可能只會讓您的用戶感到沮喪.

                  Filter Input This means that for any data input whether provided by a user on a form or provided by a file from some other source, filter out anything which does not belong. An example would be that if you expect a numeric value, filter out any non-numeric characters. Another example would be limit/ensure the maximum length of data. However, you don't need to get to crazy with this. For example, if you expect a line of text that can contain literally any combination of characters, then trying to come up with a filter will probably only frustrate your users.

                  因此,您通常會將輸入數據存儲在數據庫中,并預先提供一些可選的過濾功能.

                  So, you generally would store input data in your database as provided with optionally some filtering before hand.

                  轉義輸出轉義輸出的意思是正確保護給定媒體的數據.大多數時候,這個媒體是一個網頁(html).但是,它也可以是純文本、xml、pdf、圖像等.對于 html,這意味著使用 htmlspecialchars()htmlentities()(您可以閱讀差異此處).對于其他媒體類型,您將根據需要進行轉義/轉換(如果合適,則根本不進行轉換).

                  Escape Output What is meant by escape output is to properly make safe the data for a given media. Most of the time, this media is a web page (html). But, it can also be plain text, xml, pdf, image, etc. For html, this means using htmlspecialchars() or htmlentities() (you can read up on the differences here). For other media types, you would escape/convert as appropriate (or not at all if appropriate).

                  現在,您的問題是您是否應該對將用作 sql 查詢參數的輸入數據使用 htmlspecialchars().答案是不.您不應以任何方式修改數據.

                  Now, your question is whether or not you should use htmlspecialchars() on input data that will be used as sql query parameters. The answer is no. You should not modify the data in any way.

                  是的,$_POST 中包含的數據應該被視為危險.這就是為什么您應該 1) 使用準備好的語句和綁定參數來防止 sql 注入,以及 2) 如果將 $_POST 中的數據放在 html 中,則正確轉義/轉換它.

                  Yes, the data contained in $_POST should be considered dangerous. Which is why you should 1) guard against sql injection using prepared statements and bound parameters as you are doing and 2) properly escape/convert data found in $_POST if you place it in html.

                  有許多 PHP 框架可以為您處理這些細節,我建議您選擇并使用一個.但是,如果您不這樣做,您仍然可以構建安全可靠的應用程序.無論您是否使用框架,我強烈建議您閱讀OWASP.不這樣做只會給您的網絡應用程序帶來安全噩夢.

                  There are many frameworks for PHP which handle these details for you and I recommend you pick and use one. However, if you do not, you can still build a safe and secure application. Whether you use a framework or not, I strongly suggest that you read the recommendations suggested by OWASP. Failure to do so will only result in a security nightmare for your web application.

                  這篇關于在 PDO 中使用 htmlspecialchars 函數準備和執行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                      <tbody id='U3Kug'></tbody>
                    <tfoot id='U3Kug'></tfoot>

                    1. <legend id='U3Kug'><style id='U3Kug'><dir id='U3Kug'><q id='U3Kug'></q></dir></style></legend>
                        <bdo id='U3Kug'></bdo><ul id='U3Kug'></ul>

                          <i id='U3Kug'><tr id='U3Kug'><dt id='U3Kug'><q id='U3Kug'><span id='U3Kug'><b id='U3Kug'><form id='U3Kug'><ins id='U3Kug'></ins><ul id='U3Kug'></ul><sub id='U3Kug'></sub></form><legend id='U3Kug'></legend><bdo id='U3Kug'><pre id='U3Kug'><center id='U3Kug'></center></pre></bdo></b><th id='U3Kug'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='U3Kug'><tfoot id='U3Kug'></tfoot><dl id='U3Kug'><fieldset id='U3Kug'></fieldset></dl></div>

                          <small id='U3Kug'></small><noframes id='U3Kug'>

                            主站蜘蛛池模板: av网站免费观看 | 欧美一区二区在线 | 成人乱人乱一区二区三区软件 | 国产免费一区二区 | 日韩a在线 | 久久毛片 | 鸳鸯谱在线观看高清 | 99久久精品国产一区二区三区 | 国产精品久久久久无码av | 婷婷一级片 | 狠狠的日| 麻豆av电影网 | 久久久91| 亚洲精品天堂 | 久久久青草婷婷精品综合日韩 | 日韩久久久一区二区 | 久久精品欧美电影 | 亚洲欧美激情网 | 免费福利视频一区二区三区 | 一级大片免费 | 日韩免费视频 | 国产精品一二三区 | 精品一区二区电影 | 精品一区二区三区在线观看国产 | 一区二区三区四区日韩 | 91精品国产91久久久久久最新 | 国产免费自拍 | 精品久久电影 | 免费视频中文字幕 | 羞羞的视频在线 | 一区视频 | 久久中文字幕一区 | 国产精品片 | 国产综合久久 | 欧美日韩在线综合 | 天天干狠狠操 | 国产精品久久久久久久久久久久久 | 久久在看 | 国产欧美日韩在线播放 | 国产精品亚洲成在人线 | 欧美一区二区在线播放 |