Jump to content

Gracefully fail if not required version of PHP


KenDRhyD

Recommended Posts

I know that I can use phpversion() and version_compare() to check for the version of PHP being used, but....

 

How can I gracefully display an error message if an older version of PHP is installed when the actual code in the page requires more recent parsing?

 

For example, my main PHP page uses try/catch blocks, which are not supported in PHP 4. I can tell my clients that PHP 5 is required, but when one of them attempts to get the web site working with PHP 4 installed, they simply get a parse error telling them the line of the code on or after the try keyword. Since the PHP code cannot be executed until the entire file passes parsing, how can I get a meaningful error message?

If your program requires a run-once of configuration script during installation, start off with a low-complexity (php <5 compatible) "compatibility check" page. It could check register_globals, magic_quotes_gpc, etc along with the version of php and display a message if the server is configured incorrectly.

If your program requires a run-once of configuration script during installation, start off with a low-complexity (php <5 compatible) "compatibility check" page. It could check register_globals, magic_quotes_gpc, etc along with the version of php and display a message if the server is configured incorrectly.

 

Yes, but the problem is that this 'page' is not displayed unless there is a problem, and the 'real' page is displayed and the user can see the page name in the address bar. Knowing the name of the page permits them to bypass the page by directing the browser directly to that page.

 

Well if you mean "is there a way to stop them from even attempting a parse on a page once they've uploaded it to their server without first going through my configuration script" then no, there really is no way. As you've said you need to parse the page before you can run any php code on it, and if it won't parse (because of php5 code on a php4 server) then there's no php solution for you.

 

That said, I do believe you can add a configuration script to the auto_prepend_file directive in the php.ini file that checks compatibility before the requested file is parsed (and causes an error because of an older php version), but that seems like an awful lot of trouble and overhead for something like this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.