Phpinspectionsea: PHP as Module vs CGI - Warning on using features with different results

Created on 22 Feb 2019  路  7Comments  路  Source: kalessil/phpinspectionsea

I recently wrote code that didn't act as locally tested. My live system is a MAMP with PHP as module, where my live system runs PHP as CGI.

In my particular case it was:

$_SERVER['REQUEST_URI'];
//vs
$_SERVER['REDIRECT_URL'];

Locally the later gave me the path without URL parameter, whereas live it just gave me index.php.

I think it would be good to have a warning on using code that have ambiguous results depending on the used technology to run PHP. Obviously for the code above, but this probably is not limited to that.

In my personal case this was a custom code, only for my company website, but generally this would help to prevent that ambiguous and thus broken code.

enhancement

Most helpful comment

We need only to start, community will share more cases over the time =)

All 7 comments

Hi @apermo, gladly. Since I'm not using globals often, what would be the best alternative for the both $_SERVER['REQUEST_URI'] and $_SERVER['REDIRECT_URL']? As I understand, the both of them are not working the same way is module/CGI modes.

REQUEST_URI is the same on both, REDIRECT_URIdiffers, depending on the implementation of PHP.

Ok, then we need to complain about using REDIRECT_URI and propose using something instead. Should we propose using REQUEST_URI or something else instead?

Yes, but I'm sure there are more things that differ between CGI and Module, but I'm not aware of all differences.

We need only to start, community will share more cases over the time =)

Bebo beep, the StaleBot is here. For one year nothing have happened here. It would be great if someone looked into details here within next 21 days when I'll close it.

Re-opening

Was this page helpful?
0 / 5 - 0 ratings