Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
FuelPHP URI becomes query string. How to fix this?
  • Hi.

    I have URL like this.
    http://localhost/fuelphp << This is FuelPHP based URL and index.php file is in here.
    http://localhost/fuelphp/my/app/uri << /my/app/uri is URI from my module's page.

    In the controller inside /my/app/uri. If I echo out $_SERVER['QUERY_STING'] it should be empty but I get /my/app/uri as a result.
    How to fix this? I never happens to me before.

    PHP 5.6.25
    Server API CGI/FastCGI
    Windows
  • Any particular reason why (you think) this need to be fixed?

    For FastGCI installs, the rewrite rule is

        RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

    which causes the URI to become part of the query string, but it is the only way to pass it on to the CGI script (in this case index.php).

    If your URI contains a query string, it will just become a part of it, the Input class will unravel both when it processes the URI.

    In a Fuel app, there should never be a need to access any PHP global directly.
  • Because if I get value via \Input::server('QUERY_STRING') from non fast CGI there is no URI in it.
    But if I get this from fast CGI there is URI in it. It should return the same value.
  • HarroHarro
    Accepted Answer
    No, it doesn't. I just explained you why.

    The values in $_SERVER reflect your environment, there are more values that are different whether or not you use FastCGI. $_SERVER['QUERY_STRING'] contains the query string that is passed on to PHP by FastCGI, so it is correct. It wouldn't work if it had different contents.
  • Can you create a dummy test.php in your public folder, dumping $_SERVER?

    I'm interested in: PATH_INFO, ORIG_PATH_INFO, SCRIPT_NAME, REQUEST_URI and QUERY_STRING.

    If could be that in your case https://github.com/fuel/core/blob/1.9/develop/classes/input/instance.php#L194 is to blame, but that should only happen if the QUERY_STRING had both a URI and a (real) query string. Perhaps something is different in your environment.
  • And can you do the same, but then from your app bootstrap.php, before calling Fuel::init(), requesting the controller from your opening post?
  • @Harro

    I'm writing a comment on this old thread because it's the only one I can find on the subject and it seems it wasn't really solved.

    In my opinion, the FuelPHP behavior of modifying the Query String is wrong. I'm using FuelPHP 1.8. 

    I am using Fast CGI on Windows (dev) and FPM with mod_proxy_fcgi on Linux (prod) and on both systems the Query String gets modified (as coded in .htaccess). Let's see the example of environment variables, which are the same on both environments:

    [FastCGI, PHP-FPM with proxy_fcgi]
    - sets up $_GET['/transactions'] without reason
    - $_SERVER['REQUEST_URI'] = /transactions?test=1
    - $_SERVER['QUERY_STRING'] = /transactions&test=1 (wrong, should be "test=1")

    Can you explain why the QUERY_STRING is modified inside .htaccess? It should be the same for every environment. I know there was some troubles with correct path for CGI installs, but I don't see this is the case.

    To support my argument I can say, that this causes problems with built-in FuelPHP pagination as the QUERY_STRING gets looped.

    I changed the .htaccess value:
    From: RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    To: RewriteRule ^(.*)$ index.php [L]

    And everything is working like a charm on both: FastCGI and FPM with PROXY_FCGI, which is probably the best way to run PHP at the moment.

  • Where in your app have you dumped $_SERVER and $_GET? 

    If not in public/index.php, can you do that, and tell me what QUERY_STRING, REQUEST_URI and SCRIPT_NAME (and PATH_INFO if it exists) exactly is?

    Because it could also be a bug in Input::uri() where all this data is parsed and recreated if needed.


  • Sure. I dumped the data in the public/index.php right after php opening tag.


    $_SERVER['QUERY_STRING'] = /transactions&test=1
    $_SERVER['REQUEST_URI'] = /transactions?test=1
    $_SERVER['SCRIPT_NAME'] = /index.php

    PATH_INFO does not exist.
  • So I need a think about how to address this problem, and not create yours.

    The reason for that (odd) rewrite btw is because there are combinations of Apache en php-fpm versions that do not pass the QUERY_STRING, so this is why it is reconstructed in the Input class.
  • Think I've been able to address it:

      'QUERY_STRING' => string 'test=1' (length=6)
      'REQUEST_URI' => string '/transactions?test=1' (length=20)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion