Hudzilla.org - the homepage of Paul Hudson
Contents > Writing PHP > Distributing your code Wish List | Report Bug | About Me ]

19.7.6     Cross-platform code 4: Coping with php.ini differences

This is NOT the latest copy of this book; click here for the latest version.

If you have made a lot of changes to your php.ini file, or indeed any changes from the default php.ini file, it is possible that scripts your write will not work elsewhere. There are three common culprits: extensions, register_globals, and safe mode.

If you have enabled an extension which is not enabled in someone else's php.ini file, people deploying your script will get lots of errors about undefined functions. The best way around this, other than adding warnings about required extensions in your readme file, is to have a checkconfig.php file that runs checks on the current configuration to make sure it has the correct extensions available.

Register_globals is a setting that, when enabled, makes PHP put all user-submitted variables into the global scope automatically - not very secure, as you can imagine. The problem is that this setting was enabled by default in old versions of PHP 4, which means that a lot of people might have this setting enabled still. If someone gives you a script that requires register_globals being enabled, it is probably best that you do not use it - it is not worth the security risk. Similarly you should avoid writing scripts that rely on register_globals, even if you choose to enable it locally - most people out there leave it disabled, as recommended.

The third problem you are likely to encounter when people use your scripts elsewhere is safe mode. With safe mode enabled there is very little you can do to ensure your script will work without flaw, because administrators can disable whichever functions they deem unsafe - even very basic functions. If you think there might be problems with your script (reading files is the most common problem), your best bet is to provide a list of what your script requires with your documentation - that way, people stuck with safe mode enabled can at least see what the problem is, and maybe even ask their ISP to relax their restrictions a little.





<< 19.7.5 Cross-platform code 3: Path and line separators   19.7.7 Cross-platform code 5: Checking the PHP version with phpversion() and version_compare() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is three plus four?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow