开发者

Do PHP files with multiple extensions gets parsed?

开发者 https://www.devze.com 2023-04-09 00:50 出处:网络
I have a habit of making file backups by adding the .bak extension (file.ext.bak). Imagine if I have a config in PHP, config.php and I want to backup that file by adding the .bak extension, will the

I have a habit of making file backups by adding the .bak extension (file.ext.bak).

Imagine if I have a config in PHP, config.php and I want to backup that file by adding the .bak extension, will the file get parsed or will you see the source code if a client accidentally end up at that url? Is it server dependent?

I've tried some test开发者_StackOverflows on a MAMP server but it seems to be parsing


It depends on the server configuration. It is a bad habit to keep those files accessible by browsers anyway, but should you want to, check your httpd.conf for these lines:

<IfModule mod_php5.c>
  AddType application/x-httpd-php .php .phtml .php3
  AddType application/x-httpd-php-source .phps
</IfModule>

This will tell the webserver that .php files actually contain code to be executed.

  • You could add the .bak file there (but it remains a bad habit).
  • Another workaround would be to just rename the file to file.bak.ext instead).
  • The best solution remains moving the files to somewhere where the browser can't access them, out of the document root and other mappings.


will the file get parsed or will you see the source code if a client accidentally end up at that url?

Usually, you will see the source code because the .bak extension is not registered to be parsed with PHP. Needless to say, this is very dangerous!

Is it server dependent?

Yes. It is possible to configure the server to parse those files, but it's not part of any default configuration I know.

The better solution is to do it the other way round: filename.bak.php

0

精彩评论

暂无评论...
验证码 换一张
取 消