<tfoot id='4OW1Q'></tfoot>
    <legend id='4OW1Q'><style id='4OW1Q'><dir id='4OW1Q'><q id='4OW1Q'></q></dir></style></legend>
    • <bdo id='4OW1Q'></bdo><ul id='4OW1Q'></ul>

    1. <small id='4OW1Q'></small><noframes id='4OW1Q'>

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

      1. 带有 GET 请求的 PHP 开关

        PHP switch with GET request(带有 GET 请求的 PHP 开关)
        <i id='YNJNq'><tr id='YNJNq'><dt id='YNJNq'><q id='YNJNq'><span id='YNJNq'><b id='YNJNq'><form id='YNJNq'><ins id='YNJNq'></ins><ul id='YNJNq'></ul><sub id='YNJNq'></sub></form><legend id='YNJNq'></legend><bdo id='YNJNq'><pre id='YNJNq'><center id='YNJNq'></center></pre></bdo></b><th id='YNJNq'></th></span></q></dt></tr></i><div id='YNJNq'><tfoot id='YNJNq'></tfoot><dl id='YNJNq'><fieldset id='YNJNq'></fieldset></dl></div>
      2. <legend id='YNJNq'><style id='YNJNq'><dir id='YNJNq'><q id='YNJNq'></q></dir></style></legend>
          • <tfoot id='YNJNq'></tfoot>

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

                • <bdo id='YNJNq'></bdo><ul id='YNJNq'></ul>
                    <tbody id='YNJNq'></tbody>
                • 本文介绍了带有 GET 请求的 PHP 开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为我的网站构建一个简单的管理区域,我希望 URL 看起来像这样:

                  I am building a simple admin area for my site and I want the URLs to look somewhat like this:

                  http://mysite.com/admin/?home
                  http://mysite.com/admin/?settings
                  http://mysite.com/admin/?users
                  

                  但我不确定如何检索请求的页面,然后显示所需的页面.我在我的交换机上试过这个:

                  But I am not sure how I would retrieve what page is being requested and then show the required page. I tried this in my switch:

                  switch($_GET[])
                  {
                      case 'home':
                          echo 'admin home';
                          break;
                  }
                  

                  但我收到此错误:

                  致命错误:第 40 行无法使用 [] 读取 C:path owebdirectoryadminindex.php

                  有什么办法可以解决这个问题吗?我想避免为 GET 请求设置值,例如:

                  Is there any way around this? I want to avoid setting a value to the GET request, like:

                  http://mysite.com/admin/?action=home
                  

                  如果你知道我的意思.谢谢.:)

                  If you know what I mean. Thanks. :)

                  推荐答案

                  使用 $_SERVER['QUERY_STRING'] –包含 ? 之后的位:

                  Use $_SERVER['QUERY_STRING'] – that contains the bits after the ?:

                  switch($_SERVER['QUERY_STRING']) {
                      case 'home':
                          echo 'admin home';
                          break;
                  }
                  

                  您可以更进一步地使用此方法并使用如下网址:

                  You can take this method even further and have URLs like this:

                  http://mysite.com/admin/?users/user/16/
                  

                  只需使用 explode() 将查询字符串拆分为段,获取第一个并将其余部分作为方法的参数传递:

                  Just use explode() to split the query string into segments, get the first one and pass the rest as arguments for the method:

                  $args = explode('/', rtrim($_SERVER['QUERY_STRING'], '/'));
                  $method = array_shift($args);
                  
                  switch($method) {
                      case 'users':
                          $user_id = $args[2];
                  
                          doSomething($user_id);
                          break;
                  }
                  

                  这种方法在许多采用 MVC 模式的框架中都很流行.完全摆脱 ? 的另一个步骤是在 Apache 服务器上使用 mod_rewrite,但我认为这有点超出了这个问题的范围.

                  This method is popular in many frameworks that employ the MVC pattern. An additional step to get rid of the ? altogether is to use mod_rewrite on Apache servers, but I think that's a bit out of scope for this question.

                  这篇关于带有 GET 请求的 PHP 开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 文件不起作用?)
                • <i id='BIsac'><tr id='BIsac'><dt id='BIsac'><q id='BIsac'><span id='BIsac'><b id='BIsac'><form id='BIsac'><ins id='BIsac'></ins><ul id='BIsac'></ul><sub id='BIsac'></sub></form><legend id='BIsac'></legend><bdo id='BIsac'><pre id='BIsac'><center id='BIsac'></center></pre></bdo></b><th id='BIsac'></th></span></q></dt></tr></i><div id='BIsac'><tfoot id='BIsac'></tfoot><dl id='BIsac'><fieldset id='BIsac'></fieldset></dl></div>

                  <tfoot id='BIsac'></tfoot>

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

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

                    <bdo id='BIsac'></bdo><ul id='BIsac'></ul>
                      <tbody id='BIsac'></tbody>