dongming4994 2019-06-30 19:14
浏览 52

GAE - PHP7 - 如何通过前端控制器传递GET参数

Google Apps Engine for PHP7 now requires a "front-controller". These are the URL I need to manage:

  • /sitemap.xml
  • /app/myPHP ?param1=value &param2=value2

my source folder has the following files

  • index.php (front controller)
  • home.php
  • gen_sitemap.php
  • myPHP.php

so I coded my front-controller (index.php) as

<?php
switch ($_SERVER['REQUEST_URI']) {
    case '/':
        require 'home.php';
        break;

    case '/sitemap.xml':
        require 'gen_sitemap.php';
        break;

    case '/app/myPHP':
        require 'myPHP.php';
        break;

    default:
        echo "no page " . time();
        break;
}

But it is not parsing correctly the URLs:

https://myProject.appspot.com/ --> home.php ok

https://myProject.appspot.com/?p="hello" --> no page

https://myProject.appspot.com/sitemap.xml --> sitemap.php ok

https://myProject.appspot.com/sitemap.xml?p="h" --> no page

https://myProject.appspot.com/app/myPHP --> myPHP.php ok

https://myProject.appspot.com/app/myPHP?p="h" --> no page

How do I fix this front-controller ? thank you,

  • 写回答

1条回答 默认 最新

  • doufen3838 2019-06-30 19:38
    关注

    The Switch condition may not work properly since it is comparing "REQUEST_URI". The PHP's SERVER global variable key REQUEST_URI will probably have the full path with the query string. Rather try the key "SCRIPT_NAME" or "PATH_INFO"

    Suggestion: First check what all key values are available in the $_SERVER variable then choose which key value to use for adding your switch command.

    Example: print_r($_SERVER); as the first line of your code

    Reference: https://www.php.net/manual/en/reserved.variables.server.php

    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染