duanliao6077 2012-05-13 02:59
浏览 25
已采纳

访问DOCUMENT_ROOT之外的PHP类文件

I am confused as to what constitutes " best practice" for the structure of a PHP web-based application. Reading this site there are a number of suggestions. One structure frequently mentioned is "do not have any php files inside the document root". While this sounds like good practice, I cannot see how it works - the web server doesn't recognise anything outside the document root. I assume here that document root is the public access directory, something like as shown below:

app-
  |
  - htdocs - document root
  | |
  | - index.php
  | - css/
  | - images/
  |
  - PHP classes in here/
  - Other PHP classes in here.../

Or is it that "app" in the above example is the document root, and the htdocs dir is the publicly accessible area of the site structure?

Following on from that, how do I ensure public access is not available for the files in dirs other than htdocs please?

  • 写回答

2条回答 默认 最新

  • douyao1994 2012-05-13 03:05
    关注

    The concept is simple, especially if you use a front controller based framework whether it be your own or an existing one (like the Zend Framework). When all of the requests come through a central controller the files necessary to handle the request are included as necessary. Included files do not have to be in the web root to work. They just need to be available to the controller to be included and then executed. So, only your controller needs to be in the web root. Everything else can be outside of it.

    FYI, this also works with non-OOP applications. You just need to include the files you need in each page.

    What does need to be in the web root are any asests like images, styelsheets, javascript files, etc. that are requested by the browser.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)