<bdo id='judvA'></bdo><ul id='judvA'></ul>

  • <legend id='judvA'><style id='judvA'><dir id='judvA'><q id='judvA'></q></dir></style></legend>
    <tfoot id='judvA'></tfoot>

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

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

        $_GET 作为 PHP 函数中的参数

        $_GET as parameters in PHP functions($_GET 作为 PHP 函数中的参数)

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

        <tfoot id='QfB75'></tfoot>

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

                    <tbody id='QfB75'></tbody>

                • <legend id='QfB75'><style id='QfB75'><dir id='QfB75'><q id='QfB75'></q></dir></style></legend>
                  本文介绍了$_GET 作为 PHP 函数中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有同样的问题,但是...我正在根据使用标头的 if 语句将用户重定向到通过函数构造的动态页面.要使该函数正常工作,它需要在标头的 GET 部分中传递参数.

                  I have the same question but...I'm redirecting the user depending on an if statement using headers to a dynamic page that is constructed through a function. For that function to work properly, it needs the parameters passed in the GET portion of the headers.

                  根据所提供的答案,这是一种不好的做法.我应该怎么做?

                  According to what to the answers provided, this is a bad practice. What way should I be doing it?

                  function page($title,$msg){
                      $title = $_GET['title'];
                      $msg = $_GET['msg'];
                      echo '<h1>'.$title.'</h1>';
                  
                      echo '<p>';
                      switch($msg){
                          case 1:
                              echo 'dwasdwadawdwadwa';
                          break;
                          case 2:
                              echo 'wasdadwadwdad';
                          break;
                          default:
                              echo 'wadasdasd';
                          break;
                      }
                      echo '</p>';
                  }
                  

                  ps:请随时指出您认为错误的任何其他内容.

                  ps: feel free to point out anything else you see wrong.

                  我发现了这个,但它并没有真正帮助我.

                  I found this but it doesn't really help me.

                  推荐答案

                  您链接的问题的答案表明函数不应依赖任何外部(例如全局)变量.$_GET$_POST(以及其他)是超级全局变量",这是 PHP 的一种语言特性,使它们可以在任何范围内使用.这意味着它们可能会在脚本中的任何地方意外修改.

                  The answer to the question you linked suggests that functions should not rely on any external (e.g. global) variables. $_GET and $_POST (amongst others) are 'super globals', a language feature of PHP that makes them available in any scope. This means they may be unexpectedly modified from anywhere in your scripts.

                  帮助避免这种情况的一种方法是避免在方法中使用超级全局变量,而是 - 正如另一个问题的答案所暗示的那样 - 改为要求您将从超级全局变量中获得的变量的参数.

                  One way to help avoid this is to avoid using super globals in methods and instead - as the answer to the other question suggests - is to instead require parameters for the variables you would otherwise get from the super globals.

                  例如,代替:

                  function add_user() {
                    $user = $_GET['user'];
                    // ...
                  }
                  add_user();
                  

                  你会使用:

                  function add_user($user) {
                    // ...
                  }
                  add_user($_GET['user']);
                  

                  在您的情况下,您想要的是:

                  In your situation, what you would want is:

                  function page($title, $msg){
                    echo '<h1>'.$title.'</h1>';
                    echo '<p>';
                    switch($msg){
                      case 1:
                        echo 'dwasdwadawdwadwa';
                      break;
                      case 2:
                        echo 'wasdadwadwdad';
                      break;
                      default:
                        echo 'wadasdasd';
                      break;
                    }
                    echo '</p>';
                  }
                  

                  然后,当你调用 page 时,你会调用它:

                  Then, when you call page you would call it as:

                  page($_GET['title'], $_GET['msg']);
                  

                  这篇关于$_GET 作为 PHP 函数中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <tfoot id='F0Nx8'></tfoot>

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

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

                            <tbody id='F0Nx8'></tbody>
                            <legend id='F0Nx8'><style id='F0Nx8'><dir id='F0Nx8'><q id='F0Nx8'></q></dir></style></legend>