Strange Stuff Happens with PHP in CGI Mode

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Strange Stuff Happens with PHP in CGI Mode

Post by volomike »

I noticed tonight that if PHP was in CGI mode, my $_SERVER variables come back a good bit different than when PHP is loaded as a standard Apache2 module. Just wanted to pass on as an FYI to you, in case you are racking your brains.

This seems to be very important if you are doing handsome/pretty URLs with RewriteRule statements. The $_SERVER['SCRIPT_NAME'] you might be parsing for might need to be changed to $_SERVER['ORIG_SCRIPT_NAME']. And if you were expecting the '.php' to be added in when you do $_SERVER['PHP_SELF'], even on a page where you were doing RewriteRule -- this will work on a normal host and you'll see the '.php' there. But in CGI mode, $_SERVER['PHP_SELF'] does not show the '.php' and you have to parse for it and add it in. In my case, I had to trap for '/articles/' and replace as '/articles.php/' after reading $_SERVER['PHP_SELF'] so that the rest of my code would work like it does on a normal host.

Now, why is PHP in CGI mode? Well, my client was using lunarpages.com, and I guess they do this. I, however, use a2hosting.com, and they load PHP just fine. Another odd thing was that at least until this year, lunarpages.com made all .php files run as PHP4 and you had to use an AddHandler/AddType code block in .htaccess to specify that .php would run with PHP5. But in 2009, they seem to have fixed this and now the PHP pages run as PHP5 by default. So, I could remove that AddHandler/AddType code block.
Post Reply