I put the file extension as . phtml and only Chrome is displaying all the code. Why?

Asked

Viewed 281 times

0

I put the file extension as .phtml and only in Google Chrome is displaying all the page code, but in other browsers is interpreting normally.

The page is loaded inside a iframe. If I change the extension to .php, works.

Can anyone tell me why this occurs only in Chrome?

  • You are using zend framework?

  • You are not using a framework.

  • 1

    Give more details of what you are trying to do, the way it is are many possibilities.

  • 1

    Why are you wearing phtml?

  • Using Apache? Using any template preprocessing library? Using Zend? Why are you using PHTML?

  • When we took the project the pages were already with this extension phtml. I don’t know why they used.

  • 1

    Maybe this will help answer the question What are . phtml files and when I should use them?

  • 1

    @Miguelbast using Apache? You can add a condition for them to be interpreted as PHP.

  • 1

    The strange thing is that he said that in Chrome does not work, but in others work.

  • this is strange because it already has the apache configuration to interpret the extension and the problem only occurs in Chrome. Vixi, Jesus!

  • Possible duplicate of Migrate from PHP 5.2.9 to PHP 5.6.8

  • It may sound dumb, but... You’re actually accessing the web server URL, not a file://, right?

  • Thanks @bfavaretto, the url was correct. The problem was solved thanks.

  • Was the answer below resolved? If not, could you put your own answer to help others with the same problem? Thank you!

  • The answer lowers not solved.

Show 10 more comments

1 answer

3

I believe that it is not actually working in any browser, but other browsers other than Chrome should be downloading the file instead of displaying or should be interpreting as text/html, which ignores php tags making you think they are html tags, Chrome must be interpreting as plain/text.

How I answered here:

Understand that the Apache, Ngnix and other equivalent servers do not use standard extensions, in fact it is you who customize, you can even invent your own extension if you wish, for example by editing the httpd.conf in the apache:

AddType application/x-httpd-php .php
AddType application/x-httpd-php .miguel

Ready, it will be possible to use .miguel as an extension to run php files. You can still add index files with custom extensions for example:

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.html index.htm index.miguel
</IfModule>

So why .phtml and .php are custom things anyway and if you want to add do this:

AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml

And that:

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.html index.htm index.phtml
</IfModule>

Note: But note that not all accommodations will allow you to customize the extensions and the best thing is to stay in the most common one is to use .php for everything, or maybe a mod_rewrite and not using extensions

  • Already have this configuration in apache.

  • @Miguelbatist then if you write it in a . phtml <?php echo 1 + 2; ?> in Firefox or IE it is displaying 3? Note that I edited the beginning of the answer.

  • that’s right. I didn’t check.

  • 1

    @Miguelbast a note, after changing the settings and adding such extra extensions it is necessary to restart Apache completely because otherwise this will have no effect.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.