php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

PATH_INFO vs ORIG_PATH_INFO

Open jayfar opened this issue 10 years ago • 2 comments

I've been using your great library developing on my test server with everything working perfect for a few weeks now. Thanks for the great library!

Today, I uploded my code to a production environment (1and1 hosted server) and the library stopped working. After about an hour of digging, I found the 1and1 server was setting $_SERVER['ORIG_PATH_INFO'] and not $_SERVER['PATH_INFO'].

In my brief research, I guess some server setups do this: http://stackoverflow.com/questions/5629683/serverpath-info-and-serverorig-path-info-in-php

In the constructor (function __construct) of your REST_CRUD_API class, I found this line of code:

if (!$request) {
    $request = isset($_SERVER['PATH_INFO'])?$_SERVER['PATH_INFO']:'';
}

I changed my copy of your library to be a bit more generic and handle both PATH_INFO and ORIG_PATH_INFO cases:

if (!$request) {
    $request = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : '');
}

FYI... In case you want to update your master copy.

Thanks again for the library!

jayfar avatar Mar 10 '16 21:03 jayfar

Thank you for you kind words, your feedback is much appreciated.

if (isset($_SERVER['ORIG_PATH_INFO'])) $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];

Is what I would have written at the top of "api.php" to counter this non-standard behaviour.

mevdschee avatar Mar 10 '16 21:03 mevdschee

Added some documentation so others can easily find such issues: 0e03c74b56bbc5658923155c643fede0bfde5c9c

mevdschee avatar Mar 10 '16 22:03 mevdschee