.Php files need a .php extension?

I am creating a bunch of php documents that are included. .cfg for configuration files, .tpl for template structure files, .dlf for document layout files, dbh for database connections, etc.

Now they are called .tpl.php, .dlf.php, etc. But do I need to have a .php extension too? If not, are there any extensions I should not use? e.g. .exe for executable files ..

+7
file php
source share
2 answers

You can change the server configuration to include other file extensions as PHP

In Apache, you can add to this:

<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> 

if you include files, then any extension will do:

in script.php:

 include 'includes/foo.inc'; include 'inlcudes/bar.whatever'; 

everyone will work

+3
source share

From Hiding PHP to PHP.net :

Another tactic is to configure web servers, such as apache, to analyze various file types via PHP, either using the .htaccess directive or in the apache configuration file itself. Then you can use the misleading file extensions:

 # Make PHP code look like unknown types AddType application/x-httpd-php .bop .foo .133t 

So, you can add the .htaccess rule, which means that your server processes .tpl , .dlf , etc., as if they were PHP files, for example:

 AddType application/x-httpd-php .tpl .dlf .dbh 

However, if you use only include or require , it doesn't matter which extension you use:

 include "inc/template.tpl"; require "inc/database.dbh"; require_once("inc/config.ext.php.url.tpl.cfg"); 
+3
source share

All Articles