访问 public_html 文件夹外的 php 代码 [英] Accessing php code outside public_html folder

查看:26
本文介绍了访问 public_html 文件夹外的 php 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Twitter 引导程序作为前端和 PHP 作为背后的代码来设置一个新网站.

I'm trying to setup a new website using Twitter bootstrap as the front-end and PHP as the code behind.

我使用的目录结构如下,相当标准

The directory structure I'm using is as follows and fairly standard

c:\xampp\htdocs\app
c:\xampp\htdocs\app\application\configs
c:\xampp\htdocs\app\application\modules
c:\xampp\htdocs\app\data\
c:\xampp\htdocs\app\data\logs
c:\xampp\htdocs\app\data\sessions
c:\xampp\htdocs\public_html\
c:\xampp\htdocs\public_html\css
c:\xampp\htdocs\public_html\js
c:\xampp\htdocs\public_html\img

我的 Apache 配置相当简单,包括

My Apache config is fairly straight forward and consists of

<VirtualHost *:80>

ServerName vinner.localhost
DocumentRoot C:/xampp/htdocs/app/public_html
SetEnv APPLICATION_ENV "development"
<Directory C:/xampp/htdocs/app/public_html> 
    DirectoryIndex index.php index.html index.htm \
               default.php default.asp default.shtml default.html default.htm \        AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

以前我在/public_html 文件夹中有我的 PHP 代码,但这显然不是很好的做法,所以我将它移到 c:\xampp\htdocs\app\application\modules 但是我不知道如何将 POST 查询直接指向 PHP 页面,或者创建一个通用的 PHP 模板/包含文件,以便轻松访问我的 PHP 页面.

Previously I had my PHP code inside the /public_html folder but this obviously isn't great practise so I've moved it to c:\xampp\htdocs\app\application\modules however I can't figure out how to point either POST queries directly to PHP pages, or to create a generic PHP template/include file so my PHP pages are easily accessible.

推荐答案

您应该在public_html"目录中有一个文件,通常称为index.php".然后,您的 Web 服务器规则(例如 .htaccess 或服务器配置)将所有请求(或者可能不是针对public_html"中存在的文件的所有请求)指向该public_html/index.php".这通常是public_html"下唯一的 PHP 文件,但有时可能有多个用于不同目的(例如,用于提供图像的不同文件).

You should have a file, usually called "index.php", in the "public_html" directory. Then your web server rules (e.g. .htaccess or server configuration) points all requests (or perhaps, all requests that aren't for files that exist in "public_html") to that "public_html/index.php". This is usually the only PHP file under "public_html", but sometimes there may be multiple for different purposes (e.g. a different one for serving images).

从那里您可以使用相对路径包含其余代码,以下每个都是等效的(public_html/index.php"中的代码):

From there you can include the rest of your code using relative paths, each of the following is equivalent (code in "public_html/index.php"):

include __DIR__ . '/../application/[application-code].php';

还有:

include dirname(__DIR__) . '/application/[application-code].php';

其中application-code"是应用程序的入口点,通常命名为bootstrap.php".

Where "application-code" is an entry point to your application, often named something like "bootstrap.php".

这篇关于访问 public_html 文件夹外的 php 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆