Category Archives: PHP

Change PHP Mapping for .php File Extension

Applies to: PHP, Apache

Let’s imagine your apache webhost has both PHP4 and PHP5 installed, and the default mapping for .php files is linked to PHP4. Now the question is, how do you change that mapping to get PHP5¬†linked to .php files? (assuming you don’t have administrative priviledges on the webhost)

Workaround: You may choose to simply name your php files with the .php5 file extension if there are only a few scripts that require PHP5 (not really the answer to our problem).

Solution:¬†If you don’t want to rename all your scripts to .php5, create a .htaccess file (or edit the existing .htaccess file, if you already have one). You can create this file using a text editor such as Notepad, WordPad, vi, nano, etc. and place the following line in the text file:

AddType x-mapp-php5 .php

Save the text file as .htaccess in the folder where you need to use PHP5 (or upload the file to the correct folder). The settings specified in the .htaccess file are recursive meaning that the settings will apply to the current folder where the file is saved as well as all subfolders.

Have fun! :-)

Redirect Webpage with PHP

Applies to: PHP, Websites

You can use a simple PHP script to redirect a user from the page they entered to a different web page. One reason you may want to do this is that the page they are trying to access no longer exists. Using this method, they can be seamlessly transfered to the new page without having to click a link to continue.

  • Users are redirected quickly and seamlessly
  • When using the ‘Back’ button, the user is taken to the last viewed page, not the redirect page
  • Works on all browsers

Here’s How:

header( ‘Location:’ ) ;

Change the code on the redirect page to be simply this. You need to replace the URL above with the URL you wish to direct to.

Note: Be sure that you do not have any text sent to the browser before this, or it will not work. Your safest bet is to simply remove all content from the page but the redirect code.