<legend id='I1RHE'><style id='I1RHE'><dir id='I1RHE'><q id='I1RHE'></q></dir></style></legend>

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

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

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

      1. PHP 安全 $_GET 与否

        PHP safe $_GET or not(PHP 安全 $_GET 与否)

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

                • <small id='JSv5d'></small><noframes id='JSv5d'>

                  <i id='JSv5d'><tr id='JSv5d'><dt id='JSv5d'><q id='JSv5d'><span id='JSv5d'><b id='JSv5d'><form id='JSv5d'><ins id='JSv5d'></ins><ul id='JSv5d'></ul><sub id='JSv5d'></sub></form><legend id='JSv5d'></legend><bdo id='JSv5d'><pre id='JSv5d'><center id='JSv5d'></center></pre></bdo></b><th id='JSv5d'></th></span></q></dt></tr></i><div id='JSv5d'><tfoot id='JSv5d'></tfoot><dl id='JSv5d'><fieldset id='JSv5d'></fieldset></dl></div>
                    <tbody id='JSv5d'></tbody>
                • <legend id='JSv5d'><style id='JSv5d'><dir id='JSv5d'><q id='JSv5d'></q></dir></style></legend>
                  <tfoot id='JSv5d'></tfoot>

                  本文介绍了PHP 安全 $_GET 与否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们有网址:

                  http://site.com/index.php?action=show
                  

                  $_GET['action'] 用于模板中检查 ?action= 的值:

                  $_GET['action'] is used in templates to check value of ?action=:

                  switch ($_GET['action']) {
                      case = "show" {
                          $match_show = true;
                      }
                  }
                  

                  在其他地方:

                  echo $_GET['action'];
                  

                  使用这种结构绝对安全吗?

                  Is it absolutely safe to use this constructions?

                  如何使它们安全?

                  谢谢.

                  推荐答案

                  开关的事情是好的,因为你正在与一个硬编码的值进行比较(但是,它是 case "show": btw).

                  The switch thing is okay, because you are comparing against a hard-coded value (however, it's case "show": btw).

                  正如@Bruce 在评论中提到的,您还应该添加一个 default: 案例以捕获不在列表中的值或空值:

                  As @Bruce mentions in the comments, you should add a default: case as well to catch values that are not on the list, or empty values:

                  switch ($_GET['action']) {
                  
                      case "show":
                          $match_show = true;
                          break;
                  
                      default: 
                          // value is not on the list. React accordingly.
                          echo "Unknown value for 'action'". 
                  
                  }
                  

                  第二件事有潜在的危险,因为有可能将 HTML 和更重要的 JavaScript 注入到文档正文中.您应该在回显之前对变量应用 htmlspecialchars() .

                  The second thing is potentially dangerous, as it would be possible to inject HTML and more importantly, JavaScript into the document body. You should apply a htmlspecialchars() on the variable before echoing it.

                  这篇关于PHP 安全 $_GET 与否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)
                  <tfoot id='Nodyh'></tfoot>
                  <i id='Nodyh'><tr id='Nodyh'><dt id='Nodyh'><q id='Nodyh'><span id='Nodyh'><b id='Nodyh'><form id='Nodyh'><ins id='Nodyh'></ins><ul id='Nodyh'></ul><sub id='Nodyh'></sub></form><legend id='Nodyh'></legend><bdo id='Nodyh'><pre id='Nodyh'><center id='Nodyh'></center></pre></bdo></b><th id='Nodyh'></th></span></q></dt></tr></i><div id='Nodyh'><tfoot id='Nodyh'></tfoot><dl id='Nodyh'><fieldset id='Nodyh'></fieldset></dl></div>
                    <tbody id='Nodyh'></tbody>

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

                      <bdo id='Nodyh'></bdo><ul id='Nodyh'></ul>
                      • <legend id='Nodyh'><style id='Nodyh'><dir id='Nodyh'><q id='Nodyh'></q></dir></style></legend>