X
Tippen Sie hierhin, um die Version dieser Website für Mobilgeräte aufzurufen.

Hilfeforum

Firefox tries to download php files

Veröffentlicht

Hi

I'm running a MAMP PRO installation on my OS X 11.6 which works perfectly (Apache & MYSQL). All of a sudden Firefox asks for download when browising to a .php file on my localhost. Could anybody give me a hint on why this happesn?

Thanks, Tom

Hi I'm running a MAMP PRO installation on my OS X 11.6 which works perfectly (Apache & MYSQL). All of a sudden Firefox asks for download when browising to a .php file on my localhost. Could anybody give me a hint on why this happesn? Thanks, Tom

Mehr Details zum System

Installierte Plugins

  • Shockwave Flash 31.0 r0

Anwendung

  • User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:62.0) Gecko/20100101 Firefox/62.0

Weitere Informationen

Shadow110 1072 Lösungen 14836 Antworten
Veröffentlicht

Hi, unfortunately can not give you a idea as to why.

Please go to Options --> General --> Applications and check for php in the list. If it is in the list Click on it and tell it what you want to do.

Firefox has never processed PHP code natively. You need to have server software running locally that processes the PHP code and that sends the resulting file as text/plain instead of application/x-httpd-php.

Please see if anything on this page helps : https://stackoverflow.com/questions/27565664/prompted-to-download-when-opening-php-files-in-firefox

Hi, unfortunately can not give you a idea as to why. Please go to Options --> General --> Applications and check for php in the list. If it is in the list Click on it and tell it what you want to do. Firefox has never processed PHP code natively. You need to have server software running locally that processes the PHP code and that sends the resulting file as text/plain instead of application/x-httpd-php. *http://www.w3schools.com/php/func_http_header.asp Please see if anything on this page helps : https://stackoverflow.com/questions/27565664/prompted-to-download-when-opening-php-files-in-firefox
cor-el
  • Top 10 Contributor
  • Moderator
17588 Lösungen 159104 Antworten
Veröffentlicht

A web server needs to process the PHP code and send the resulting file as text/html to the browser. Firefox doesn't process PHP code and can only work with HTML, so if Firefox wants shows the "open with" dialog and wants to download then this means that the files are not send with the correct content-type.

A web server needs to process the PHP code and send the resulting file as text/html to the browser. Firefox doesn't process PHP code and can only work with HTML, so if Firefox wants shows the "open with" dialog and wants to download then this means that the files are not send with the correct content-type.
jscher2000
  • Top 10 Contributor
8799 Lösungen 71970 Antworten
Veröffentlicht

Hi Tom, do you mean an address like this:

http://localhost/index.php

Could you check the content-type the server is sending. One way is to open the Network Monitor in the lower part of a tab -- either

  • "3-bar" menu button > Web Developer > Network
  • (menu bar) Tools > Web Developer > Network
  • (Mac) Command+option/alt+e

-- then try to load the page in the top part of the tab. Cancel the download dialog, click the request in the Network Monitor, and inspect the Response headers in the pane on the right for the Content-Type.

What you want to see is text/html but probably it's something that Firefox doesn't think can be displayed in a tab.

If Content-Type is normal, look for a Content-Disposition header ("attachment" forces a download).

Hi Tom, do you mean an address like this: http://localhost/index.php Could you check the content-type the server is sending. One way is to open the Network Monitor in the lower part of a tab -- either * "3-bar" menu button > Web Developer > Network * (menu bar) Tools > Web Developer > Network * (Mac) Command+option/alt+e -- then try to load the page in the top part of the tab. Cancel the download dialog, click the request in the Network Monitor, and inspect the Response headers in the pane on the right for the Content-Type. What you ''want'' to see is '''text/html''' but probably it's something that Firefox doesn't think can be displayed in a tab. If Content-Type is normal, look for a Content-Disposition header ("attachment" forces a download).
cor-el
  • Top 10 Contributor
  • Moderator
17588 Lösungen 159104 Antworten
Veröffentlicht

You need something like this to make the server process the file and send the file with the correct content-type. Otherwise the server may send it as application/x-httpd-php and that makes Firefox present the open with dialog.

<?php header('Content-Type: text/html; charset=utf-8'); header('Vary: Accept'); ?>
You need something like this to make the server process the file and send the file with the correct content-type. Otherwise the server may send it as application/x-httpd-php and that makes Firefox present the open with dialog. <pre><nowiki><?php header('Content-Type: text/html; charset=utf-8'); header('Vary: Accept'); ?></nowiki></pre>
Veröffentlicht

Fragesteller

jscher2000 said

What you want to see is text/html but probably it's something that Firefox doesn't think can be displayed in a tab.

That's exactly what I see - nevertheless FF opens the dialog box... This happens on many localhost sites on my computer, but not on all of them. Some installations on localhost run fine (couple of joomla and WP sites and phpbb blogs - that's why I know that apache and mysql are running on my machine).

Any other ideas on what might cause this behaviour? Thanks for all your help, Tom

''jscher2000 [[#answer-1156402|said]]'' <blockquote> What you ''want'' to see is '''text/html''' but probably it's something that Firefox doesn't think can be displayed in a tab. </blockquote> That's exactly what I see - nevertheless FF opens the dialog box... This happens on many localhost sites on my computer, but not on all of them. Some installations on localhost run fine (couple of joomla and WP sites and phpbb blogs - that's why I know that apache and mysql are running on my machine). Any other ideas on what might cause this behaviour? Thanks for all your help, Tom
FFus3r 50 Lösungen 757 Antworten
Veröffentlicht
see this answer: * https://support.mozilla.org/en-US/questions/941019#answer-378719
Veröffentlicht

Fragesteller

ok, I deleted the mimeTypes.rfd file - no success. I also reset the plugin.disable_full_page_plugin_for_types without any success. FF is still trying to download the php file...

ok, I deleted the mimeTypes.rfd file - no success. I also reset the plugin.disable_full_page_plugin_for_types without any success. FF is still trying to download the php file...
jscher2000
  • Top 10 Contributor
8799 Lösungen 71970 Antworten
Veröffentlicht

So other

http://localhost/myapp/index.php

files work normally, but the one

http://localhost/myapp/bad.php

does not. And you have ruled out the obvious issues:

  • loaded using http:// not file://
  • Content-Type header received by Firefox is text/html (or text/plain)
  • Content-Disposition header is not present or if it is present does not contain "attachment"

It doesn't make sense for Firefox not to render text/html content retrieved via http:// in a tab if not instructed to treat it as a download.


Does Safari show the file in a tab?

Could you test in Firefox's Safe Mode? In its Safe Mode, Firefox temporarily deactivates extensions, hardware acceleration, and some other advanced features to help you assess whether these are causing the problem.

If Firefox is not running: Hold down the option/alt key when starting Firefox. (On Windows, hold down the Shift key instead of the option/alt key.)

If Firefox is running: You can restart Firefox in Safe Mode using either:

  • "3-bar" menu button > "?" Help button > Restart with Add-ons Disabled
  • (menu bar) Help menu > Restart with Add-ons Disabled

and OK the restart.

Both scenarios: A small dialog should appear. Click "Start in Safe Mode" (not Refresh).

Any improvement?

So other http://localhost/myapp/index.php files work normally, but the one http://localhost/myapp/bad.php does not. And you have ruled out the obvious issues: * loaded using http:// not file:// * Content-Type header received by Firefox is text/html (or text/plain) * Content-Disposition header is not present or if it is present does not contain "attachment" It doesn't make sense for Firefox not to render text/html content retrieved via http:// in a tab if not instructed to treat it as a download. ---- Does Safari show the file in a tab? Could you test in Firefox's Safe Mode? In its Safe Mode, Firefox temporarily deactivates extensions, hardware acceleration, and some other advanced features to help you assess whether these are causing the problem. ''If Firefox is not running:'' Hold down the option/alt key when starting Firefox. (On Windows, hold down the Shift key instead of the option/alt key.) ''If Firefox is running:'' You can restart Firefox in Safe Mode using either: * "3-bar" menu button > "?" Help button > Restart with Add-ons Disabled * (menu bar) Help menu > Restart with Add-ons Disabled and OK the restart. ''Both scenarios:'' A small dialog should appear. Click "Start in Safe Mode" (''not'' Refresh). Any improvement?
Veröffentlicht

Fragesteller

that's correct: some localhost applications start well, other don't (there's no coincidence between WP, Joomla or phpbb - one phpbb site starts, the other one not).

I've tried in FF safe mode. No success. Safari as well downloads the php file and does not show it in a tab. So it might be related to MAMP PRO?

that's correct: some localhost applications start well, other don't (there's no coincidence between WP, Joomla or phpbb - one phpbb site starts, the other one not). I've tried in FF safe mode. No success. Safari as well downloads the php file and does not show it in a tab. So it might be related to MAMP PRO?
cor-el
  • Top 10 Contributor
  • Moderator
17588 Lösungen 159104 Antworten
Veröffentlicht

Can you post the HTTP response headers as shown in the Network Monitor?

Note that current Firefox releases use handlers.json and no longer use mimeTypes.rdf, so you can try to remove handlers.json instead.

Can you post the HTTP response headers as shown in the Network Monitor? *https://developer.mozilla.org/en/Tools/Network_Monitor Note that current Firefox releases use handlers.json and no longer use mimeTypes.rdf, so you can try to remove handlers.json instead.

Geändert am von cor-el

Veröffentlicht

Fragesteller

ok, removed handlers.json - no effect. Here are response headers from Network Monitor:

Accept-Ranges bytes Connection Keep-Alive Content-Type application/x-httpd-php Date Thu, 20 Sep 2018 20:03:08 GMT ETag "66857e0-20c6-5764702a9eec0" Keep-Alive timeout=5, max=100 Last-Modified Thu, 20 Sep 2018 05:44:03 GMT Server Apache Transfer-Encoding chunked Request headers (472 B) Accept text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language de-CH,en-US;q=0.7,en;q=0.3 Cache-Control no-cache Connection keep-alive Cookie gaShowOptOut=false; _ga=GA1.1.277754305.1536175087 DNT 1 Host localhost Pragma no-cache Upgrade-Insecure-Requests 1 User-Agent Mozilla/5.0 (Macintosh; Intel …) Gecko/20100101 Firefox/62.0

ok, removed handlers.json - no effect. Here are response headers from Network Monitor: Accept-Ranges bytes Connection Keep-Alive Content-Type application/x-httpd-php Date Thu, 20 Sep 2018 20:03:08 GMT ETag "66857e0-20c6-5764702a9eec0" Keep-Alive timeout=5, max=100 Last-Modified Thu, 20 Sep 2018 05:44:03 GMT Server Apache Transfer-Encoding chunked Request headers (472 B) Accept text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language de-CH,en-US;q=0.7,en;q=0.3 Cache-Control no-cache Connection keep-alive Cookie gaShowOptOut=false; _ga=GA1.1.277754305.1536175087 DNT 1 Host localhost Pragma no-cache Upgrade-Insecure-Requests 1 User-Agent Mozilla/5.0 (Macintosh; Intel …) Gecko/20100101 Firefox/62.0
cor-el
  • Top 10 Contributor
  • Moderator
17588 Lösungen 159104 Antworten
Veröffentlicht

You can see: Content-Type: application/x-httpd-php

This means that a server isn't processing the PHP code and this means that Firefox offers to download the file like I wrote above. This will only work with Firefox if the server processes the PHP code and sends a text/html content-type.

Do you have this PHP directive at the start of the file to instruct the server to process the file?

<?php header('Content-Type: text/html; charset=utf-8'); header('Vary: Accept'); ?>
You can see: Content-Type: application/x-httpd-php This means that a server isn't processing the PHP code and this means that Firefox offers to download the file like I wrote above. This will only work with Firefox if the server processes the PHP code and sends a text/html content-type. Do you have this PHP directive at the start of the file to instruct the server to process the file? <pre><nowiki><?php header('Content-Type: text/html; charset=utf-8'); header('Vary: Accept'); ?></nowiki></pre>
jscher2000
  • Top 10 Contributor
8799 Lösungen 71970 Antworten
Veröffentlicht

There's a file somewhere in Apache where you associate each file extension with a content type. I am surprised php is not already handled. As a fallback you can put it in a .htaccess file at the root of the application.

There's a file somewhere in Apache where you associate each file extension with a content type. I am surprised php is not already handled. As a fallback you can put it in a .htaccess file at the root of the application.
Veröffentlicht

Fragesteller

ok, the PHP directive is present at the start of the file to instruct the server to process the file. But of no success.

How do I define this to the .htaccess file? (sorry, but I never had to deal with those things... ;-)

Thanks for all your help!

ok, the PHP directive is present at the start of the file to instruct the server to process the file. But of no success. How do I define this to the .htaccess file? (sorry, but I never had to deal with those things... ;-) Thanks for all your help!
jscher2000
  • Top 10 Contributor
8799 Lösungen 71970 Antworten
Veröffentlicht

Do you currently have any .htaccess files in the directories of the problem web pages?

Do you currently have any .htaccess files in the directories of the problem web pages?
Roland Tanglao
  • Administrator
72 Lösungen 785 Antworten
Veröffentlicht

Hi tcgass

This is a Firefox user support forum; it is not a web developer forum for debugging your PHP web application. I appreciate the awesome advice that jscher2000, cor-el and many others have tried on this forum to help you but it's not really this forum's area of expertise!

Please use the appropriate channel (tag it PHP on stackoverflow.com for example?) as per:

https://support.mozilla.org/en-US/kb/where-go-developer-support

Cheers!

...Roland

Hi tcgass This is a Firefox user support forum; it is not a web developer forum for debugging your PHP web application. I appreciate the awesome advice that jscher2000, cor-el and many others have tried on this forum to help you but it's not really this forum's area of expertise! Please use the appropriate channel (tag it PHP on stackoverflow.com for example?) as per: https://support.mozilla.org/en-US/kb/where-go-developer-support Cheers! ...Roland