<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 开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                • <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>