pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="gnflo6s" id='EqEU6'><tfoot id='EqEU6'></tfoot><dl id='EqEU6'><fieldset id='EqEU6'></fieldset></dl></div>

      1. 在 PDO 中使用 htmlspecialchars 函數(shù)準(zhǔn)備和執(zhí)行

        Using htmlspecialchars function with PDO prepare and execute(在 PDO 中使用 htmlspecialchars 函數(shù)準(zhǔn)備和執(zhí)行)
          <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="j32vjtg" id='HFQuG'><tfoot id='HFQuG'></tfoot><dl id='HFQuG'><fieldset id='HFQuG'></fieldset></dl></div>
                • 本文介紹了在 PDO 中使用 htmlspecialchars 函數(shù)準(zhǔn)備和執(zhí)行的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  使用htmlspecialchars()函數(shù)的PHP PDO在表單驗(yàn)證和數(shù)據(jù)庫(kù)查詢中將特殊字符轉(zhuǎn)換為HTML實(shí)體真的有必要嗎?

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

                  例如,我有一個(gè)或多或少具有簡(jiǎn)單登錄系統(tǒng)的網(wǎng)站:

                  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);
                  

                  請(qǐng)注意,除了所討論的函數(shù)之外,我還使用了類型轉(zhuǎn)換.那么,有必要嗎?或者我可以安全地使用 $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']; ?

                  推薦答案

                  您的困惑很常見,因?yàn)闀突ヂ?lián)網(wǎng)(包括 php.net)上的信息和示例具有誤導(dǎo)性或歧義.在開發(fā) Web 應(yīng)用程序時(shí),您可以學(xué)到的最重要的事情是 過(guò)濾輸入,轉(zhuǎn)義輸出.

                  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.

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

                  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.

                  因此,您通常會(huì)將輸入數(shù)據(jù)存儲(chǔ)在數(shù)據(jù)庫(kù)中,并預(yù)先提供一些可選的過(guò)濾功能.

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

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

                  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).

                  現(xiàn)在,您的問(wèn)題是您是否應(yīng)該對(duì)將用作 sql 查詢參數(shù)的輸入數(shù)據(jù)使用 htmlspecialchars().答案是不.您不應(yīng)以任何方式修改數(shù)據(jù).

                  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 中包含的數(shù)據(jù)應(yīng)該被視為危險(xiǎn).這就是為什么您應(yīng)該 1) 使用準(zhǔn)備好的語(yǔ)句和綁定參數(shù)來(lái)防止 sql 注入,以及 2) 如果將 $_POST 中的數(shù)據(jù)放在 html 中,則正確轉(zhuǎn)義/轉(zhuǎn)換它.

                  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 框架可以為您處理這些細(xì)節(jié),我建議您選擇并使用一個(gè).但是,如果您不這樣做,您仍然可以構(gòu)建安全可靠的應(yīng)用程序.無(wú)論您是否使用框架,我強(qiáng)烈建議您閱讀OWASP.不這樣做只會(huì)給您的網(wǎng)絡(luò)應(yīng)用程序帶來(lái)安全噩夢(mèng).

                  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.

                  這篇關(guān)于在 PDO 中使用 htmlspecialchars 函數(shù)準(zhǔn)備和執(zhí)行的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

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

                      <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="aptloxh" id='U3Kug'><tfoot id='U3Kug'></tfoot><dl id='U3Kug'><fieldset id='U3Kug'></fieldset></dl></div>

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

                            主站蜘蛛池模板: 凝胶成像仪,化学发光凝胶成像系统,凝胶成像分析系统-上海培清科技有限公司 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | 橡胶弹簧|复合弹簧|橡胶球|振动筛配件-新乡市永鑫橡胶厂 | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | POS机办理_个人POS机免费领取 - 银联POS机申请首页 | 小区健身器材_户外健身器材_室外健身器材_公园健身路径-沧州浩然体育器材有限公司 | 光伏支架成型设备-光伏钢边框设备-光伏设备厂家| 承插管件_不锈钢承插管件_锻钢高压管件-温州科正阀门管件有限公司 | 粘度计维修,在线粘度计,二手博勒飞粘度计维修|收购-天津市祥睿科技有限公司 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 超细|超微气流粉碎机|气流磨|气流分级机|粉体改性机|磨粉机|粉碎设备-山东埃尔派粉体科技 | 精准猎取科技资讯,高效阅读科技新闻_科技猎 | 耐驰泵阀管件制造-耐驰泵阀科技(天津)有限公司 | 大流量卧式砂磨机_强力分散机_双行星双动力混合机_同心双轴搅拌机-莱州市龙跃化工机械有限公司 | 元拓建材集团官方网站 | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 美甲贴片-指甲贴片-穿戴美甲-假指甲厂家--薇丝黛拉 | 电梯装饰-北京万达中意电梯装饰有限公司 | 搜活动房网—活动房_集装箱活动房_集成房屋_活动房屋 | HDPE储罐_厂家-山东九州阿丽贝防腐设备 | 细砂提取机,隔膜板框泥浆污泥压滤机,螺旋洗砂机设备,轮式洗砂机械,机制砂,圆锥颚式反击式破碎机,振动筛,滚筒筛,喂料机- 上海重睿环保设备有限公司 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | 拉力测试机|材料拉伸试验机|电子拉力机价格|万能试验机厂家|苏州皖仪实验仪器有限公司 | 艾默生变频器,艾默生ct,变频器,ct驱动器,广州艾默生变频器,供水专用变频器,风机变频器,电梯变频器,艾默生变频器代理-广州市盟雄贸易有限公司官方网站-艾默生变频器应用解决方案服务商 | 美的商用净水器_美的直饮机_一级代理经销商_Midea租赁价格-厂家反渗透滤芯-直饮水批发品牌售后 | 超声波乳化机-超声波分散机|仪-超声波萃取仪-超声波均质机-精浩机械|首页 | 屏蔽泵厂家,化工屏蔽泵_维修-淄博泵业 | 国产离子色谱仪,红外分光测油仪,自动烟尘烟气测试仪-青岛埃仑通用科技有限公司 | 手持式线材张力计-套帽式风量罩-深圳市欧亚精密仪器有限公司 | 高压无油空压机_无油水润滑空压机_水润滑无油螺杆空压机_无油空压机厂家-科普柯超滤(广东)节能科技有限公司 | 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | PVC快速门-硬质快速门-洁净室快速门品牌厂家-苏州西朗门业 | 北京浩云律师事务所-法律顾问_企业法务_律师顾问_公司顾问 | 西门子代理商_西门子变频器总代理-翰粤百科 | WTB5光栅尺-JIE WILL磁栅尺-B60数显表-常州中崴机电科技有限公司 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 生态板-实木生态板-生态板厂家-源木原作生态板品牌-深圳市方舟木业有限公司 | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 西安微信朋友圈广告投放_微信朋友圈推广_西安度娘网络科技有限公司 | PSI渗透压仪,TPS酸度计,美国CHAI PCR仪,渗透压仪厂家_价格,微生物快速检测仪-华泰和合(北京)商贸有限公司 |