PHP, eval, and HTTP response codes

The PHP eval() function is an odd beast. I’ve encountered this a few times before, wherein a site will display just fine, but Google won’t index it, and if you review the headers for the page (using curl or telnet), you’ll see that instead of the expected 200 OK response, you’ll get a “HTTP/1.0 500 Internal Server Error” — bad juju for all of your hard SEO work.

Taking a look at the site’s error_log may reveal a PHP error — often a syntax error or some such. However, the line of code to which it refers is just an eval() statement for an included file.

If the eval’d code has an error, the code running the eval statement will work just fine; however, because of the error in the eval’d code, the response code header will return a 500. This, interestingly enough, will only occur if display_errors is set to off.

The ideal solution is to fix the code that is being eval’d.

The hackish way, which I prefer because I’m lazy, is to do something terrible such as:

[code lang=”PHP”]// There’s got to be a better way to do this.
ini_set(“display_errors”, “on”);
ini_set(“display_errors”, “off”);

The response code will now be 200 and Google will be happy; however, the problem isn’t *really* solved…

Leave a Reply