Does PHP need the .php extension ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys,

When I use PHP I give my file the .php extension. I always wondered if it
could be an .htm page with a <script> block that the PHP resides in, the
same way you would do JavaScript. If you can do it that way are there any
benifits to that method ?

Take care,

Re: Does PHP need the .php extension ?

Quoted text here. Click to load it
    Right now you probably have a directive like this in your
httpd.conf file (or your ISP does).

    AddType application/x-httpd-php .php4 .php .php3 .inc .inf .phtml

    It identifies the extensions which should be processed by the
php interpreter before output is sent to the browser.  I believe
you can also include this directive in a .htaccess file in your
area and add .htm to the list. This would send all your files
throught the interpreter and those that do not contain PHP code
would just be passed through....

    You mention Javascript, but that is a bit different.  The
interpretation of that happens at your browser -- all the PHP
work is done at the server.

    Hope this helps.
John Murtari                              Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211)  "TheBook.Com" (TM) /

Re: Does PHP need the .php extension ?

Cyrus D. wrote:
Quoted text here. Click to load it

1. You can use the .htm extension and tell the server through .htaccess
to treat any .htm file as a php file
2. Within a html page (which is treated as php via the above method) you
can have a php block by surrounding the block with: <?php and ?>

If you like to have a "clean" and easily maintainable site, I would
personnaly prefer a seperation of languages as much a possible.
In that case there really would be no benefits to using the above method.

Each to their own however, you may find it useful.


Re: Does PHP need the .php extension ?

*** Cyrus D. wrote/escribió (Tue, 09 Nov 2004 16:56:46 GMT):
Quoted text here. Click to load it

Your web browser must have a rule about what files should be passed to PHP
interpreter (you probably don't want to parse JPEG files ;-) That rule is
normally based in file extension. There's also a tweak called x-bit hack
that works under Unix.

-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions

Re: Does PHP need the .php extension ?

 .oO(Alvaro G Vicario)

Quoted text here. Click to load it


Quoted text here. Click to load it

Sure, but it's just a matter of configuration. If you want your .foo and files be handled by PHP - do it. The server does what you tell him
to do.


Site Timeline