Viewing PHP pages

Since upgrading to Tiger I've run into a strange problem. When trying to preview web pages I'm working on in Dreamweaver in Safari I get the source code in the main browser window instead of the actual rendered page. The extension of the file is .php. This only seems to occur with a local file. For example:

file:///Users/scottfeiner/Sites/Pandeiro/site/index.php

But when a .php page is viewed from a web server there's no problem.

Anyone have any ideas? This is driving me nuts!

Posted on Jun 14, 2005 11:57 AM

Reply
44 replies

Jun 15, 2005 3:34 PM in response to Scott F.

Hi Scott,

I'm using Firefox 1.0.8, but cannot say that explains the different behaviour over your Firefox 1.04. On my OS X10.4.1/Firefox 1.0.8, I just selected Firefox's
b Open File...
menu item and selected the file
b test.php
from the standard file dialog.

As
b Jasper
pointed out, it's sometimes unclear exactly what a browser should do. The important thing is that
b (1)
you've got Safari 2.x working as you want it (by enabling web sharing); and
b (2)
you've got alternate browsers if you don't want to use (1).

This is slightly off-topic, and I realize that this has been a frustrating day for you, but if you want some insight into how frustrating it is for the Apple engineers trying to figure out the
b best
or
b right
behaviour for Safari, have a gander sometime at lead engineer David Hyatt's surfin' safari blog.

best wishes,
...ben

Jun 16, 2005 1:08 AM in response to Scott F.

Very interesting discussion guys. I have Tiger, but not installed yet. Ben, your testpage works perfectly in Safari 1.2.4. I'll have to try it in 2.0.

I don't want to hijack this thread but I need some help with a php script and the knowledgable posts here inspired me to ask this. Would someone be willing to help me out? We can take this elsewhere but I do need some help and I am getting desperate.

I have just launched my first website (using Dreamweaver MX 2004) which has a rather involved form. I have formmail working but I need to add a script for uploading capabilites for the user in the same form. That's where I am stuck.

Any help for a newbie would be much appreciated.

Thanks,
John

Jun 17, 2005 3:46 PM in response to Ben Schmidt

Hi Ben,

Firefox 1.0.8? Where did you find that? On the Firefox site the latest version is 1.0.4. I tried the "open file" approach instead of drag/dropping the file into Firefox, but I got the same result. The browser doesn't seem to want to open up the file on its own.

You're right that I have other browsers on hand, but it would be nice if Sarafi would behave like it did before (and come to think of it, Firefox as well) pre-Tiger. This situation makes my web dev QA a pain in the neck.

I'll check out David's blog when I get a chance and if I can I'll ask him directly why the browser doesn't behave like it used to with PHP extensions.

Thanks for the input,
Scott

Jul 31, 2005 2:05 AM in response to Scott F.

I've been wanting to track down a solution for this since upgrading to Tiger. To summarize, in Tiger, if you're not running php locally, Safari doesn't parse the html on a file with complete html, but a php extension. It reads it as text. It only parses the html if you change the ext. (to .html or .htm). Of course it reads it fine from a server with php installed.

I'm sure it used to do this, + Firefox does (for me, yes). I'm guessing this might be intentional but like the original poster, I would like this very commonly needed functionality back.

From this thread, I tested turning on Web Sharing without enabling php, and this didn't change it. Safari still reads it as text. If the issue is having the file path through the sites folder, that just isn't going to work for me, as I work with many php files that would need an extra step to move them there.

I have submitted a bug report to Apple.

Update: With only web sharing enabled, the html is only parsed on the .php file when using the http path (shown in the sharing prefs pane after enabling apache), but is still rendered as plain text through your local file path, as when previewing from BBEdit, or dragging the file into Safari. Not practical for my needs!

Jul 31, 2005 5:59 AM in response to echo

Finally, some one else who knows what I'm talking about! Thanks echo! This problem with Tiger has caused me to change my work habits for the worse. Onlyl IE (a discontinued browser!) will display the .php file locally without having to enable websharing. This just isn't acceptable.

Just to state something from an earlier posting of mine for those who might enter the thread now. These are pages with a .php extension but with ONLY html code in them.

Jul 31, 2005 12:31 PM in response to Scott F.

I don't know how FireFox is set up differently for you, but it parses the html on a .php extension fine for me. Latest version is 1.0.6. I can't see anything I set on it from default settings that change this. I have no FF extensions installed. I use FF for testing, Safari is my main browser.

The other option is to temporarily change the extension to .html

Aug 17, 2005 5:05 PM in response to echo

Ultimately I agree with you both and find this to be an annoying development setback. In my opinion it is a bug seeing how safari shouldn't pay attention to the file type but rather it should read the document type imbedded in the file. Even though my files have the .php extension my files clearly contain a doctype. Is using doctypes now considered swiss cheese? I think not. I wouldn't mind Safari parsing different extension types as text but when a DOCTYPE is supplied it should always parse it as HTML/XHTML. This is a head ache, Please fix this issue.

Aug 17, 2005 5:30 PM in response to Scott F.

Report it!
Through the Safari menu Report bugs item, the more reports, the greater attention. After I reported it through there, I realized bugzilla at the webkit open source project ( http://webkit.opendarwin.org/ ) includes the current build, so I reported it there too. It has not had any action. You can see + follow it here:

http://bugzilla.opendarwin.org/show_bug.cgi?id=4260

Sep 21, 2005 10:30 AM in response to Scott F.

I upgraded to tiger last week, and i can't swear to it, but i think i wasn't having any problems viewing php files in safari (could also be that i simply haven't noticed until now, as i switched to more print work from web work for a couple of days.)

Today, however, I updated the same computer to Adobe's Creative Suite 2, and when i drag a php file over to safari, it displays the source code.

Firefox + Mozilla always had the problem where they wouldn't handle a local php file at all, but opened Dreamweaver instead. Safari used to work, though.

I am not a techie, but I remember that in OS 9 I could set myme types and assign applications through the control panel or some browsers' preferences. That would fix what application would open what files. That seems to have vanished now. Firefox has a file types list, but i can't seem to add to it.

I also tried changing the file type of the file itself. This now lets me drag the file over to safari's icon in the doc (before safari wouldn't highlight and recognize the file as something it could open) but it's still coming up as source code only.

definitely need a patch somewhere.

Sep 25, 2005 9:09 PM in response to Scott F.

this is also driving me crazy. i saw some comments below about "why look at php files locally?"

well... since php is an embedded scripting language, parts of my site use other coding (css, html, javascript), and i want to preview my pages from my favorite editor. i'm not expecting the php to be onterpreted, but i want to test the rest of my page without uploading it. i work on 20-30 websites a year, and it is not feasiblefor me to crete a dev environment for every site i work on. and... safari can do this for my .asp and .jsp pages.

I for a prefpane called "dafault apps" which tells me that the system (tiger) thinks php is a script type, and it also has a specification for application type. i'd like to modify this to be a text/html type - and i think that'll do it... but i can;t find those settings.

Sep 26, 2005 12:34 PM in response to Web Girl

Hi Web Girl,

The problem, if I understand it correctly, is that:
1) you have a file with a suffix of
b .php

2) This file contains both
b PHP
and
b HTML
tags.
3) You want to open this file locally -- i.e. not through a webserver (local or remote)

4) When you open the file from Safari, Safari does
b not
process the
b HTML
tags.

I can understand that this is frustrating, and based on multiple reports in this thread, is a
b different
behaviour than earlier versions of OS X exhibited. But there are at least two workarounds:

1) Don't use
b Safari.app
when you have this requirement.
For example, on my PBG4/OS X 10.4.2, five other browers
b will
give you the desired behaviour -- i.e. Netscape 7.2, Mozilla 1.7.12, Firefox1.0,7 and 1.5b1, iCab 3.0b352 and Camino 1.0a1
b all
processed
b HTML
tags when opening a local file with an extension of
b .PHP

2) Or enable websharing and then open the
b .PHP
files through your local webserver -- i.e. http://localhost/testfile.php
Not only will Safari (or any other browser) process the
b HTML
tags in this case, but if you have
b PHP
enabled, then the
b PHP
tags will be processed as well.

best of luck,
...ben

Sep 26, 2005 12:48 PM in response to Chris Converse

Hi Chris,

Have you tried other browsers? On my PBG4/OS X 10.4.2, five other browers exhibited the behaviour you desired -- i.e. Netscape 7.2, Mozilla 1.7.12, Firefox1.0.7 and 1.5b1, iCab 3.0b352 and Camino 1.0a1
b all
processed
b HTML
tags when opening a local file with an extension of
b .PHP

best of luck,
...ben

PS. On the other hand, Safari 2.0.1, OmniWeb 5.1.1 & 5.1.2b1 and Shiira 1.1 all would
b not
process
b HTML
tags, when opening a local file with an extension of
b .PHP

I think one thing that these three browsers have in common is that they all use OSX's built-in WebKit. So be sure to use the
b Report Bugs to Apple...
link in Safari to let Apple know that their behaviour is a problem for your workflow.

Sep 26, 2005 2:01 PM in response to Chris Converse

I just trien camino (both versions), udpated firefox, and downloaded netscape. when i drag a php file to them, they all want to save the file someplace... no html previewing.


Hi Chris,

That's odd.
1) I created a
b .PHP
file in BBEdit containing PHP and HTML tags.

2) placed it on my Desktop

3) opened a blank browser window

4) dragged the
b .PHP
file into this window

For Camino 1.0a1, FireFox 1.0.7 & 1.5b1, Netscape 7.2, Mozilla 1.7.12 and iCab 3.0b352
b all
would open the
b .PHP
file and process the HTML tags.

After your posting, I also opened the same
b .PHP
file from each of the above browsers using their
b Open File...
menu items. All
would open the
b PHP
file and process the HTML tags,
b except
Camino whose Standard File Open Dialog would not let me choose the
b .PHP
file. (It was greyed out) I could however open this file from Camino using a URL: file:///Users/userid/Desktop/test.php

best of luck,
...ben

PS. Do you have any 3rd-party Internet plug-ins or browser enhancements in /Library/Internet Plug-Ins that might be interfering?

best of luck,
...ben

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Viewing PHP pages

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.