Here's a couple tips when using scripts on different (often shared) hosts, where ini_set doesn't work and php directives in .htaccess causes a 500 Internal Server Error.
Firstly, copy the server's php.ini file to your domain's web-root folder. To find the correct paths, use phpinfo() and look for "Configuration File (php.ini) Path" and "DOCUMENT_ROOT"
It's unlikely you'll have access to the php.ini via FTP, so instead run a script with a simple copy command (obviously inserting your paths):
exec("cp /usr/local/php/etc/php.ini /home/LinuxPackage/public_html/php.ini);
Edit the now-accessible php.ini file, and add settings like 'magic_quotes_gpc = off' at the bottom (regardless of whether they've been set earlier in the file). I also set:
[PHP]
max_execution_time = 60
max_input_time = 90
memory_limit = 64M
post_max_size = 32M
upload_max_filesize = 31M
magic_quotes_gpc = Off
Finally add the below line to your web-root htaccess file, to make the local php.ini the web-root default (so you don't need a copy in every script sub-folder):
SetEnv PHPRC /home/LinuxPackage/public_html/php.ini
Hope that helps a few people save some time!
Mike.
P.S. Using the new php_ini_loaded_file() function the whole lot could be done in three lines:
exec("cp " . php_ini_loaded_file() . " " . $_SERVER['DOCUMENT_ROOT'] . "/php.ini");
fwrite(fopen("{$_SERVER['DOCUMENT_ROOT']}/php.ini", 'a'), PHP_EOL . '[PHP]' . PHP_EOL . "magic_quotes_gpc = Off" . PHP_EOL);
fwrite(fopen("{$_SERVER['DOCUMENT_ROOT']}/.htaccess", 'a'), PHP_EOL . "SetEnv PHPRC {$_SERVER['DOCUMENT_ROOT']}/php.ini" . PHP_EOL);