Why are CodeIgniter application files in the publi

2020-06-03 08:47发布

Isn't having all of the files in public view a bad thing?

Surely things such as /system/application/config/database.php should not be publicly visible!

6条回答
Deceive 欺骗
2楼-- · 2020-06-03 09:19

You can add the following rule to your .htaccess file to further protect the system and application directories from being viewed (sends a 403 Forbidden error):

# Protect application and system files from being viewed
RewriteRule ^(application|system) - [F,L]
查看更多
ら.Afraid
3楼-- · 2020-06-03 09:22

The developers of CodeIgniter, EllisLabs, have set up the framework in this way for ease of use. It means that people wishing to try out the framework don't have to fiddle with any permissions settings on their server.

Of course on a production server, you are absolutely right, putting your PHP files in the public HTML folder is not a good idea.

A better way to organise your folders would be:

  • root
    • code_igniter
      • application_folder
        • config
        • controllers
        • models
        • ...
      • system_folder
    • public_html
      • css
      • js
      • images index.php .htaccess

The only other change to be made here would be to change line 26 of index.php to read:

$system_folder = "../../code_igniter/system-folder";
查看更多
等我变得足够好
4楼-- · 2020-06-03 09:28

Accessing the files within /system/ from a browser will not reveal any sensitive information, because the PHP will be parsed and nothing is output from those files (CI system files may even check to see if a variable has been defined that indicates the file wasn't accessed directly).

That being said, however, you should probably install your entire system folder above web root anyway.

查看更多
The star\"
5楼-- · 2020-06-03 09:30

You can always place the system directory outside the public directory. Don't forget to update paths inside the the front controller (index.php).

查看更多
劳资没心,怎么记你
6楼-- · 2020-06-03 09:41

With this structure:

/application
/system
/public
   index.php 

You can change in public/index.php these two settings and you are done

$application_folder = '../application';
$system_path = '../system';
查看更多
我只想做你的唯一
7楼-- · 2020-06-03 09:41

Jon Winstanley's answer is perfect, also don't forget to secure file uploads folder, if you have one. I did that by also moving it outside public root, and get the images using below code:

<?php
// $details = getimagesize($_GET["path"] . '/' .  $_GET["image"]);
$details = getimagesize($_GET["path"] .  strip_tags($_GET["image"]));
header ('Content-Type: ' . $details['mime']);
readfile($_GET["path"] . strip_tags($_GET["image"]));
exit;
?>
查看更多
登录 后发表回答