Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Input::get() and $_GET is being populated by the URL segment.
  • Hello all,

    I'm having trouble using GET variables with Fuel on a REST Controller.

    On my local dev server, if I have the URL:

    localhost/api/somemethod.json //extension makes no difference

    (Please note that I have not added a query string!)

    And Debug::dump(Input::get()); // OR dumping $_GET directly

    Within that controller method, I correctly get an empty array, as expected.

    However, if I copy my entire application to the production server and run the same code, I get something really strange. The output suddenly becomes:

    Variable #1:
    (Array, 1 element) ↵
    /api/somemethod_html (String): "" (0 characters)

    Why is this happening?  If I append any query string parameters, the $_GET array is correctly filled on both the local development server and the production server. But for some reason the behavior of this code seems to vary across servers.

    The code sample I am using is:

    public function get_somemethod(){
    \Fuel\Core\Debug::dump(Input::get());
    //Also happens with
    \Fuel\Core\Debug::dump($_GET);
    }

    Thanks
  • Did you change the default .htaccess that was included with Fuel (in the public directory) or do you have a setup that does not use this file?

    For different webserver environments, you need different rewrite rules. For example, for an fgci environment, you need to redirect to index.php?your/segments. If you use this rewrite in an apache/sapi environment, the question mark will indicate there's a query string attached.

    The rewrite rules included in the default .htaccess file in /public will take all these different environments into account, and selects the correct way of rewriting.
  • Harro,

    The only amendment that I had to make to the htaccess file was to change line 7 to

    Options +SymLinksIfOwnerMatch -Indexes

    As the initial value was causing a 500 server error.

    I have not amended anything else.

    You can see a full copy of the htaccess here.
  • What exact webserver setup is running on the production server?

    Can you dump $_SERVER in your index.php? If you don't want the info public, you can mail it to me at "wanwizard<at>fuelphp.com". I can use it to simulate your environment here, to see why this happens.
  • Sent you an email, Harro.
  • Thanks. I'll have a look as soon as my laptop is back up and running...
  • Any updates on this Harro?
  • No,

    my laptop (disk) crashed on Satuday, spend the entire weekend rebuilding it. It's slowly becoming usable again, so hopefully I'll have some time tonight.
  • How's that laptop looking?
  • New disk, setup from scratch, now about 90% usable... ;-) Most important, my webserver and DB, and all my virtual hosts are back up!

    I've ran the tests with the two $_SERVER dumps you mailed me, and that is not causing it. So it's PHP's internal parsing that already populates $_GET incorrectly.

    Are you using the .htaccess we've supplied, in the public folder, or using your own one? If your own, can you post it?
  • What I do notice:

    in the plain request, I see:

    "QUERY_STRING" =>  "/api/flooms.html"

    in the other one    

    "QUERY_STRING" => "/api/flooms&q=foo" ,

    Why does one have an extension, and the other one not, if you only added a query string?

Howdy, Stranger!

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

In this Discussion