Skip to main content

Copying the php.ini file

You can find another Tip on this page for how to create a custom php.ini file.  But after you create it, many hosts will require you to put a copy in each directory.  This script makes it easy.  It will copy the php.ini file from your main public directory and put one in all the subdirectories.  If you do not want it in every subdirectory, after you delete the ones you do not want you can do all future updates with the overwriteOnly flag on.

- - Start Script Here - -
<?php// set this value to Y if you only want to overwrite old php.ini files
// set this value to N if you want to put a php.ini file in every directory
$overwriteOnly "Y";

if (
$overwriteOnly == "Y") echo "Operating in Overwrite Only Mode<br><br>";$path "/home/" get_current_user() . "/public_html";$source $path "/php.ini";
if (!
file_exists($source)) die('Error - no source php.ini file');
function 
search($dir) {
  global 
$source;
  global 
$overwriteOnly;
  
$dh opendir($dir);
  while ((
$filename readdir($dh)) !== false) {
    if ( 
$filename !== '.' AND $filename !== '..' AND $filename !== 'cgi-bin' AND is_dir("$dir/$filename") ) {
      
$path $dir."/".$filename;
      
$target $path "/php.ini";
      if (!
file_exists($target) AND $overwriteOnly == "Y") {
        echo 
"$path <b>skipped - no php.ini file</b><br>";
      } else {
        echo 
"$target <br>";
        if (!
copy($source,$target)) echo "<b>Write failed for $target </b><br>";
        if (
file_exists($target)) chmod($target,0600);
    }
      
search($path);
    }
  }
  
closedir($dh);
}
search($path);
echo 
"<br>Done.";?>

- - End Script Here - -

Using a custom php.ini file
You may want to use a custom php.ini file in order to change some of the host defaults.   For example, you may want to turn register_globals = off.   If you copy the default host file, make changes, and then put it in your webspace, you may not know if your host makes further changes to the default file which could cause your file to be out-of-date.  A good solution is the following script, which you can execute manually or kick-off with cron each night.  The script reads the host default file, makes your change, and writes it to your public directory.  Now you can always have the current host default script with your changes made.  The example below changes register_globals in the default host php.ini file.

Note - you may have to change the file/directory paths in the examples below to match your hosting environment.

- - Start Script Here - -
<?php// full unix path - location of the default php.ini file at your host$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";

if (
file_exists($defaultPath)) {
  
$contents file_get_contents($defaultPath);

  
$contents .= "\n\n; USER MODIFIED PARAMETERS FOLLOW\n\n";  // comment line 
  
$contents .= "register_globals = Off \n";  // register globals off
 
  
$handle fopen($customPath'w');
  if (
fwrite($handle$contents)) {
    if (
file_exists($customPath)) chmod($customPath,0600);
    
$message "The php.ini file has been modified and copied";
  } else {
    
$message "Processing error - php.ini write failed";
  }
  
fclose($handle);
} else {
  
$message "Processing error - php.ini file not found";
}
echo 
$message;?> 

- - End Script Here - -

You may want to change other things in php.ini as well.  You can do this by repeating the append statement for as many changes as you wish to make.

For example you may want to use your own temp directory for session files.   To do this add the following append line:
$contents .= "session.save_path = /home/user/temp \n";   // user specified temp session file directory
Note the sessions directory is above the public directory for added security.

You may want to use your own temp upload directory for improved security.   To do this add the following line:
$contents .= "upload_tmp_dir = /home/user/temp \n";   // user specified temp upload directory
Note the uploads directory is above the public directory for added security.

If you want to change the maximum file upload size to something larger than 2MB, add the following:
$contents .= "upload_max_filesize = 4M \n";   // user specified max file upload size

And if you want to go larger than 8MB, also add the folowing:
$contents .= "post_max_size = 10M \n";   // user specified post max size


The above script does a chmod 600 on the custom php.ini file which should adequately protect it from prying eyes.

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 like phpbb which you do not know how to modify.

Comments

Popular posts from this blog

links

0.  https://michael67654.qowap.com/64523001/new-pos-technique-to-perk-up-your-company 1.  https://johnnydinqr.blog2learn.com/52856602/new-pos-system-to-perk-up-your-company 2.  http://edwinsqgcu.onesmablog.com/New-POS-Process-to-Perk-Up-Your-company-43309737 3.  http://chloe69246.bloguetechno.com/New-POS-Process-to-Perk-Up-Your-Business-39814721 4.  http://jacob87541.pointblog.net/New-POS-Technique-to-Perk-Up-Your-online-business-43741223 5.  http://arlette53302.thezenweb.com/New-POS-System-to-Perk-Up-Your-online-business-41464611 6.  http://devinpixna.tinyblogging.com/New-POS-Program-to-Perk-Up-Your-online-business-46354577 7.  https://rylanevsom.blog5.net/46759651/new-pos-program-to-perk-up-your-small-business 8.  https://mariowoesh.affiliatblogger.com/56515206/new-pos-system-to-perk-up-your-organization 9.  https://liam66429.diowebhost.com/60164326/new-pos-procedure-to-perk-up-your-company 10.  https://henry19219.fitnell.com/4557...

Raisonnement, la résolution de problèmes

Les chercheurs ont d'abord développé des algorithmes mimétiques raisonnement humain étapes que les gens utilisent pour résoudre le casse-tête ou faire méthode d'exclusion logique. [2] Dans les années 1980 et 1990 fin, l'étude de la grippe aviaire a développé des méthodes de traitement de l'information incertaine ou incomplète, en utilisant des concepts de probabilité et de l'économie. [3] Pour ces problèmes, les algorithmes requis matériel assez puissant pour effectuer des calculs de géant - à subir « combinaisons d'explosion »: la quantité de mémoire et le temps de calcul peut devenir invisible prendre si la résolution d'un problème difficile. La plus haute priorité est l'algorithme de recherche pour résoudre le problème.  Les gens utilisent généralement les jugements rapides et intuitifs plutôt que pas de déduction que les chercheurs en IA d'origine peuvent simuler. [5] Amnesty International a progressé en utilisant la résolution de problèmes « c...

Tracking and Securing Downloads

If you want to report or track downloads from your website, try this script.   This script will send you an email every time you have a download.   The email will tell you what file was downloaded and who did the download.   You could change this script to keep counts (store them in flat file or MySQL) if you desire. The variable $directory is the directory where the download files are located.   If you want the script in the same directory as the files then use "./" as the directory (you must always have the slash). In your html page, use the following structure as your download link (where name.txt is the file name to download): <a href="download.php?file=name.txt">download</a> Then you use the following script (called download.php): - - Start Script Here - - <?php $emailaddress  =  "email@yourdomain.com" ; $filename  =  $_GET [ 'file' ]; $directory  =  "downloads/" ; $path  =  "$directory$filename" ; putenv (...