500 Server Error When Running PHP Script
My hosting company upgraded its PHP version over the weekend and I
awoke Monday morning to none of my 404 error redirects working. I've
changed around my site a few times in the last15 years that I have
owned PCHell.com and I use a PHP redirect script to redirect customers
from old or bad URLs to the current good URLs. It works better than any
custom 404 error page because the visitor never knows they typed in a
bad URL, they just are redirected automatically to the appropriate
page. In conjunction with the .htaceess file its simple and wonderfully
effective for lowering bounce rates and
fixing 404 issues.
Suddenly though none of the redirects were working properly
and the php script was giving me the following error when it
was accessed.
Internal Server Error
The server encountered an
internal error or misconfiguration and was unable to complete your
request.
Contacting my host offered no help. They looked through the error logs
and pointed me toward issues in the script itself. They found an error
about a malformed header with this error
malformed header from
script. Bad header=
and refused to look any further into the issue assuming it was a
problem with a php script that had not changed in 5 years.
I knew it had something to do with the version of PHP that was running
on my host. So I created a test.php file that contained the following
line
<?php phpinfo(); ?>
This line should spit back the PHP version information, however when I
ran it I was greeted with another 500 Server error. This proved that
the problem lied with the version of PHP on the system and not with the
php script itself.
Solution
It turns out that in the directory where the php file existed, there
was a php.ini file that had the following information
register_globals = on
Unfortunately, This feature has been DEPRECATED as of PHP 5.3.0 and
REMOVED as of PHP 5.4.0.
I deleted the php.ini file in the associated directory and checked my
404 handler. Everything returned to functioning normally.