DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

php rendering

By: | 18 Feb 2009 2:55 am

Okay, now I`m totally confused.

When it comes to php does Internet Explorer and Firefox work differently?

When I type c:phpmyfile.php in internet explorer I don`t see the output of the php file but the entire contents of the php file.

When I type this same thing into the firefox url dialog box, firefox changes it to file:///c:/php/myfile.php in the dialog box and displays
nothing.

Any help clearing this up would be appreciated.

Thanks

Comments

Hello,

Your question doesn`t relate to your problem?? perhaps.

PHP is not parsed with direct file access. The file must be accessed via your server (http) so that the php is `run`.

Examples -

http://localhost/php/myfile.php
http://localhost/myfile.php
http://127.0.0.1/php/myfile.php
http://127.0.0.1/myfile.php
http://localhost/
http://127.0.0.1/

At least one of these link should work (straight out of this email).

To answer your question -

No and Yes

PHP is not the issue, IE and FF handle files differently irrespective of the particular file type as do other browsers.

This is a detailed issue so I will offerer a guide.

There three variables used by browsers to determine what to do with the
file -

1)File extension ie - .htm .html .png .pdf .exe .zip
2)File mime type sent back from server.
3)File contents such as %PDF or <HTML>

Some browsers use only one to determine what to do and some browsers go on to use others if the first test fails to give a result, other browsers us a combination.

In your case IE can`t see any headers (there are none as it is direct file access without a server). IE then looks at the .php and says `this is not a html file type`. Then IE looks at the file and sees that it has no html tags and it is not a binary file so it drops the file as a plain text file into the browser window.

FF also cannot see headers so it as there are none so it looks at the extension and does not have it registered as a HTML file but FF does not look at the content of the file so it gives up and does nothing.

To avoid these issues then you must always send the correct headers when using php to send non html files ie -
http://mydomain.com/gallery/pictures.php?gallery=01&picture=mypicture.png
http://mydomain.com/downloads/downloader.php?file=latestversion.zip

Hope this helps.

By: | 18 Feb 2009

PHP code is processed by a server module. Putting a Windows filepath (regardless of the format) in your browser will generally lead to disappointment. If you are running a web server with PHP installed on your local machine, you will typically place the php script in a particular directory and use a URL like:

http://localhost/script.php

to run it. This is not like when you were learning HTML, CSS or even Javascript where the display and processing is run in the browser. Under those circumstances, a filepath or URL which refers to the specific file may work.

If you have a file named "index.php" and it contains only HTML (because you plan to add PHP content later) then I have noticed recently that Firefox does not open these files. In the past I think it did. However, one should not expect the PHP code to be processed by the browser.

By: | 18 Feb 2009

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move