I am setting up a couple of PHP documents that include .cfg for configuration files, .tpl for template structure files, .dlf for document layout files, .dbh for database connections and so on.
Now they're called .tpl.php, .dlf.php etc. But do they need to have the .php extension as well?
If not are there any extensions I shouldn't be using? like .exe for executables.
From Hiding PHP on PHP.net:
Another tactic is to configure web servers such as apache to parse different filetypes through PHP, either with an
.htaccess
directive, or in the apache configuration file itself. You can then use misleading file extensions:# Make PHP code look like unknown types AddType application/x-httpd-php .bop .foo .133t
So you can add a .htaccess
rule that would mean that your server treats .tpl
, .dlf
etc as if they were PHP files, like so:
AddType application/x-httpd-php .tpl .dlf .dbh
However, if you are just using include
or require
, it doesn't matter what extension you use:
include "inc/template.tpl";
require "inc/database.dbh";
require_once("inc/config.ext.php.url.tpl.cfg");
You can change server config to enterpret other file extensions as PHP
In Apache you can add to this:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
if you include
the files, then any extension will do:
in script.php:
include 'includes/foo.inc';
include 'inlcudes/bar.whatever';
will all work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With