HTML files saved with a PHP extention
Would one be considered to be an idiot, or possibly even insane, if he/she has files that have no PHP coding in them whatsoever, and contunued to save and upload them as .php extentions, anyway?
Would one be considered to be an idiot, or possibly even insane, if he/she has files that have no PHP coding in them whatsoever, and contunued to save and upload them as .php extentions, anyway?
kazimmerman posted this at 13:18 — 16th January 2009.
He has: 698 posts
Joined: Jul 2005
Not necessarily. The file will function just the same with a PHP extension as it would with a regular HTML extension. One thing I like about automatically creating all files with PHP extensions is that if later you want to add something in PHP to the file, you don't have to save the file again with the new extension or worry about changing any Apache settings.
Kurtis
pr0gr4mm3r posted this at 14:20 — 16th January 2009.
He has: 1,502 posts
Joined: Sep 2006
Saving static files as PHP puts an extra load on the server, because it still loads the PHP engine to parse it.
However, as Kurtis said, I would agree that if there is a change of including PHP in the future, it may be best to do it that way.
Shaggy posted this at 17:55 — 16th January 2009.
They have: 121 posts
Joined: Dec 2008
As previously stated, having a plain HTML file parsed for possible PHP content will introduce a bit of 'unnecessary' load.
If you are worried about that difference, why not do a benchmark between the two to see if the overhead is significant enough for you to continue to worry?
Cheers,
Shaggy.
greg posted this at 18:27 — 16th January 2009.
He has: 1,581 posts
Joined: Nov 2005
If you might add PHP code in the files in the future, as has already been mentioned, then I think it's a very good idea.
As usually, when you add PHP to one file, you add it to many as the PHP usually requires various files to function and also offers functionality to multiple files or site wide.
Also, if you link to a page(s) with .html, then change it (them) later to .php you have to change all links to that page(s) throughout your site.
pr0gr4mm3r posted this at 18:41 — 16th January 2009.
He has: 1,502 posts
Joined: Sep 2006
A little rewrite magic could fix that:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1\.php [L]
decibel.places posted this at 18:57 — 16th January 2009.
He has: 1,494 posts
Joined: Jun 2008
for clarification, I would like to note that the code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1\.php [L]
belongs in the .htaccess file
greg posted this at 18:57 — 16th January 2009.
He has: 1,581 posts
Joined: Nov 2005
That is true, and there is also a way to make all HTML files parse PHP:
AddType application/x-httpd-php .php .htm .html
(this will vary slightly depending on server software)
Although there are downsides to both methods:
Mine makes ALL files are parsed even if they are simple plain old html, which adds server load for no reason in HTML only files.
And your method you have to add a line for every page you want to parse.
In summary, there are ways around it, but it's better practice to use .php for php files and then .html for html only.
I always use a header and footer file included in pretty much all my sites, as well as always using some other PHP even if just for simple little functionality. so I always use .php anyway.
pr0gr4mm3r posted this at 21:20 — 16th January 2009.
He has: 1,502 posts
Joined: Sep 2006
Are you talking about the .htaccess code?
greg posted this at 21:55 — 16th January 2009.
He has: 1,581 posts
Joined: Nov 2005
Yes, although get the the feeling that yours also does all PHP files.
pr0gr4mm3r posted this at 15:20 — 17th January 2009.
He has: 1,502 posts
Joined: Sep 2006
Yup, the wildcards will take any .html file.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.