Note - you may have to change the file/directory paths in the examples below to match your hosting environment.
Code: Select all
<?php
// Put all the php.ini parameters you want to change below. One per line.
// Follow the example format $parm[] = "parameter = value";
$parm[] = "register_globals = Off";
$parm[] = "session.use_trans_sid = 0";
// full unix path - location of the default php.ini file at your host
// you can determine the location of the default file using phpinfo()
$defaultPath = "/usr/local/lib/php.ini";
// full unix path - location where you want your custom php.ini file
$customPath = "/home/user/public_html/php.ini";
// nothing should change below this line.
if (file_exists($defaultPath)) {
$contents = file_get_contents($defaultPath);
$contents .= "\n\n; USER MODIFIED PARAMETERS FOLLOW\n\n";
foreach ($parm as $value) $contents .= $value . " \n";
if (file_put_contents($customPath,$contents)) {
if (chmod($customPath,0600)) $message = "The php.ini file has been modified and copied";
else $message = "Processing error - php.ini chmod failed";
} else {
$message = "Processing error - php.ini write failed";
}
} else {
$message = "Processing error - php.ini file not found";
}
echo $message;
?>
For example you may want to use your own temp directory for session files. To do this add the following line:
Code: Select all
$parm[] = "session.save_path = /home/user/temp"; // user specified temp session file directory
You may want to use your own temp upload directory for improved security. To do this add the following line:
Code: Select all
$parm[] = "upload_tmp_dir = /home/user/temp"; // user specified temp upload directory
If you want to change the maximum file upload size to something larger than 2MB, add the following:
Code: Select all
$parm[] = "upload_max_filesize = 4M"; // user specified max file upload size
Code: Select all
$parm[] = "post_max_size = 10M"; // user specified post max size
An alterative to using a custom php.ini file is to use the php function ini_set() in your scripts to modify the default php parameter values. This is probably the best solution for custom scripts, but not practical if you use applications which you do not know how to modify.
This function is documented here. Note that you can only change the php parameters listed as Changeable - PHP_INI_ALL (as shown here) using this method.