PHP - Is “include” function secure?

前端 未结 8 842
傲寒
傲寒 2020-12-06 06:28

I\'m using the \"include\" function (e.x. \"include \'header2.php\'\" or \"include \'class.users.php\'\") to add the header or session class in my website. I don\'t really r

8条回答
  •  失恋的感觉
    2020-12-06 07:29

    The biggest issue with includes is likely changing filename extension from PHP to something that doesn't get automatically executed by the web server. For example- library.inc, or config.inc. Invoking these files with a web browser will reveal the code instead of executing it - and any passwords or exploitable hints will be shown.

    Compare config.php that might have a password in it with config.inc. Pulling up config.inc would in most cases show what the database password was.

    There are programmers who use .inc extensions for libraries. The premise is that they won't be in a directory accessible by a web server. However, less security paranoid programmers might dump that file into a convenient web directory.

    Otherwise, ensure that you don't include a file that's submitted by a query string somehow. Ex: include( $_GET['menu_file'] ) <-- this is very wrong.

提交回复
热议问题