B&T's Tips & Scripts
How did you find this site?
  Search engine25 % 
  My webhost25 % 
  Another website30 % 
  Referral13 % 
  Other7 % 
The last vote was cast on June 29, 2009
B&T's Tool Box
Password Generation
Length of Password
Include Numbers
Include Uppercase Letters
Include Lowercase Letters
Include Special Characters
Password Encryption for .htpasswd
Username
Password
Hex RGB Color Conversion
Hex #
RGB
Check HTTP status code
enter full url to be checked
Domain Name / IP Resolution
enter Domain Name or IP Address

B&T's Recommendations

Site5.com

Got a Mac?

AppleChronicles.com

B&T's Tips & Scripts is a collection of Tips & Scripts to help you build a better website.  The Tips & Scripts are targeted towards the native Apache PHP MySQL environment.  Check back frequently as there will be additions and modifications.  Please read our terms of use.
B&T's Tips & Scripts is a safe website.
No pop-up ads and no evil downloads.
Search Tips & Scripts
as current the latest index of this site
Tag Definitions Language - if used
Date - most recent update
- for advanced users
- topic rating
Have you had enough programming and website building for a while?
Need a break to clear your mind?
Go to PrettyWorthless.com, where you will find nothing of value.


   Using .htaccess  

  1. .htaccess Basics Mar 9, 2006
  2. Domain & subdomain pointing May 12, 2005
  3. Automatic subdomains Jun 17, 2007
  4. Undefined subdomains Jul 20, 2008
  5. Prevent direct access to a pointer or subdomain directory Aug 15, 2006
  6. Forcing or eliminating the WWW. Feb 9, 2005
  7. Fixing the trailing slash problem May 11, 2005
  8. Friendly URLs Mar 21, 2007
  9. Rewrites and https Dec 18, 2007
  10. Blocking traffic to your website Jan 2, 2005
  11. Anti-leech May 25, 2005
  12. Fancy default index page Jan 25, 2005


   Using .htaccess/.htpasswd Password Protection  

  1. Setting up password protection Feb 9, 2005
  2. Encrypt your password for .htpasswd PHP Dec 21, 2007
  3. Auto Password Change and Email Notification PHP Dec 21, 2007
  4. Auto generate .htpasswd file PHP Dec 18, 2007
  5. Passing user authentication information to PHP PHP Jun 13, 2004


   Coding Tips  

  1. HTML "One Liners" Nov 13, 2005
  2. PHP "One Liners" PHPFeb 19, 2009
  3. JavaScript "One Liners" JavaScript Aug 25, 2007
  4. CSS examples Sep 9, 2006
  5. SQL coding examples PHP Aug 29, 2006
  6. MySQL Error Handling PHP Dec 20, 2007
  7. AJAX example JavaScript PHP Sep 24, 2006
  8. Regular Expression Rules Mar 22, 2006


   Uploads and Downloads  

  1. File Upload Script PHP Dec 20, 2007
  2. Custom Download Page PHP Dec 14, 2007
  3. Tracking and Securing Downloads PHP Dec 20, 2007


   Mail  

  1. Form Mail PHP May 5, 2009
  2. Obfuscate your email address JavaScript Nov 12, 2006
  3. Read and auto-process mail PHP Nov 12, 2004
  4. Auto-responder PHP Dec 18, 2007
  5. Display your email message count PHP Jul 30, 2004
  6. Setting up SPF Records November 11, 2008
  7. Specify a return-path for generated mail PHP Jul 18, 2006


   Working with Images  

  1. Watermark images PHP Jul 14, 2007
  2. Resize images (create thumbnails) PHP Jul 14, 2007


   Frequently Requested Website Functionality  

  1. Visitor Counter PHP Dec 14, 2007
  2. 404 Error Page (with reporting and logging) PHP Dec 20, 2007
  3. CAPTCHA PHP Aug 19, 2006
  4. Poll (voting) PHP Dec 17, 2007   see it on this page
  5. Weather PHP Jul 27, 2008
  6. FAQ Page JavaScript May 23, 2005
  7. Random/weighted banners (images), quotes & more PHP Feb 9, 2005
  8. Multiple random banners (images) PHP Feb 20, 2009
  9. Load a random image (simple) JavaScript Jan 20, 2004
  10. Image (banner) rotation JavaScript Oct 15, 2007
  11. Simple "members only" pages PHP May 13, 2005
  12. Replace banned words PHP Apr 5, 2007
  13. Get the most recent file date PHP Jan 30, 2006
  14. Moving (bouncing) Image JavaScript Nov 10, 2005
  15. Sticky default values for an input JavaScript Oct 22, 2006


   Using PHP  

  1. Creating a custom php.ini file PHP Dec 18, 2007
  2. Copying the php.ini file PHP Dec 18, 2007
  3. Deleting php.ini files PHP Dec 18, 2007
  4. Clean up your PHP scripts PHP Nov 11, 2005


   Website Managment  

  1. Tips for keeping your website secure Jan 24, 2006
  2. Using Cron Sep 13, 2005
  3. Website Monitoring PHP Jun 18, 2009
  4. Automated Site Backups PHP Dec 19, 2007
  5. Automated MySQL Backups PHP Dec 19, 2007
  6. Find File and Directory Sizes PHP Dec 14, 2007
  7. Deleting session files PHP Aug 9, 2006
  8. Search and Replace PHP Dec 14, 2007


   Other Tips  

  1. URL Validation PHP Feb 8, 2008
  2. Stop direct links to web pages PHP Jan 22, 2004
  3. Ensure your page is not opened in a frame JavaScript May 5, 2005
  4. Masking your URL in the Address Bar JavaScript Jul 20, 2004
  5. Ban or allow IP Addresses (without using .htaccess) PHP Jan 19, 20008
  6. Using Cookies PHP Sep 24, 2006
  7. View your website in different resolutions JavaScript Jan 2, 2005
 

Back to Top     Print this Tip

Creating 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 should ensure register_globals = off for improved script security.  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 changes, and writes it to your directory.  Now you can always have the current host default php.ini file with your changes made.

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

You can download this script as a .txt file.  Remember to rename the file as a .php file.

- - Start Script Here - -
<?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;
?> 

- - End Script Here - -

You may want to change other things in php.ini as well.  You can do this by repeating the $parm[] 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 line:
$parm[] = "session.save_path = /home/user/temp";   // 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:
$parm[] = "upload_tmp_dir = /home/user/temp";   // 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:
$parm[] = "upload_max_filesize = 4M";   // user specified max file upload size

And if you want to go larger than 8MB, also add the folowing:
$parm[] = "post_max_size = 10M";   // 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 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.

Rate This Topic



 
You are visitor 593,940
Last week there were 3,403 visitors
Copyright © 2004-2009