homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

AddHandler or AddType

 3:08 am on Feb 28, 2012 (gmt 0)

I've never posted in this forum, at least as I'm able to recall.

For more than a decade, I never used PHP. My primary participation has been in the Search Engine forum.

Recently I reactivated a site and resumed with a former host.
Previously the host had a PHP Form Mailer available via CP, which I used for two years.
Upon reactivation, the mailer was no longer available and I had to locate my own script.

The script instructions specified using AddType, which I did and it functioned.

Unfortunately, many visitors were only viewing a single page and no images, which was puzzling.

It turns out the Windows provides a message of malware warning Windows does not recognize this MIME type.

After searching Webmaster World I located some old threads that led me in the right direction, however took some tweaking.

I'm currently using AddHandler. The script functions and single page views have now turned in to normal access (appears the change is acceptable to Windows).

Could somebody possibly explain WHY Windows see's this as malware or perhaps point me toward some references?





 10:03 am on Feb 28, 2012 (gmt 0)

AddType and AddHandler are to do with the Apache webserver, not really PHP. You might be using these commands to instruct the server to parse certain files for PHP? What was the full AddType / AddHandler statements?


 11:52 am on Feb 28, 2012 (gmt 0)

What was the full AddType / AddHandler statements?

(per the script instructions)
AddType x-httpd-php .html

(changed to)
AddHandler x-httpd-php .html


 1:18 pm on Feb 28, 2012 (gmt 0)

As I understand it AddType tells the browser what mime-type the specified file extensions should be - in other words telling the browser how to handle the file. AddHandler, on the other hand, tells the server how to process files with the specified file extensions. They do different things.

In your case (with AddHandler) you are telling the server to send all .html files through the PHP engine.

AddType x-httpd-php .html

This looks wrong to me, I don't believe "x-httpd-php" is a valid mime-type and this probably explains your Windows error message. If anything (IMHO) it should be "application/x-httpd-php"...
AddType application/x-httpd-php .html

However (and this is where my server knowledge is flagging - so if someone else can please explain), despite seeing examples of this all over the web, I don't know why AddType would be required in this way. AFAIK the default mime-type for .html files is text/html which I would have thought would be OK?


 1:43 pm on Feb 28, 2012 (gmt 0)

AddType application/x-httpd-php .html

This is actually what the script instructions specified, however the script would not function with this line.

Did a google and went through plenty of references before locating one in which suggested removing application.
The script functioned fine after that.

Many thanks for your help.


 6:44 pm on Feb 28, 2012 (gmt 0)

The AddType / AddHandler stuff is beyond confusing and I usually end up trying several combinations before I find the one that works OK.


 7:26 pm on Feb 28, 2012 (gmt 0)

On some server configurations, both directives need to be implemented.

AddType application/x-httpd-php .php .html
AddHandler application/x-httpd-php .php .html


 5:33 pm on Feb 29, 2012 (gmt 0)

My understanding is that penders's description of what the two directives are supposed to do (and what they're for) is exactly right, but in some Apache versions it is necessary to use a workaround to achieve the desired effect on the server, which leads to the many variations of the two lines that you find. Some configurations require AddType, others AddHandler, and others require both. And the precise syntax required for each line also varies with version/configuration.

First look for a FAQ or KB page at your host with explicit instructions for their servers (usually titled something like "parse html files as php").

If none found, search online for forum posts by other users of your webhost describing what worked for them.

If none found, use random examples you find online and experiment until one works.


 6:31 pm on Feb 29, 2012 (gmt 0)

Some configurations require AddType, others AddHandler, and others require both.

I just had a quick go on my local test server which runs PHP as an Apache module and I am required to use AddType (not AddHandler) in a per directory .htaccess file in order to get .html files processed by PHP, of the form...
AddType application/x-httpd-php html

(The mime-type is somehow transmogrified into text/html when sent to the client.)

I have read that if you run PHP as CGI then you will need to use AddHandler instead. (It's funny, in my head it feels like it should be the other way round!? But as mentioned... confusing!)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved