何时使用 index.php 而不是 index.html [英] when to use index.php instead of index.html

查看:26
本文介绍了何时使用 index.php 而不是 index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 php 比较陌生.有一件非常基本的事情一直困扰着我.我知道 php 用于使网站动态化.我也知道 php 是可用于制作动态网站的众多服务器端脚本语言之一.

I am relatively new to php. There is a very basic thing that has been troubling me. I understand that php is used to make web sites dynamic. I also understand that php is one of the many server side scripting languages that can be used to make dynamic web sites.

然而,我不明白的是我什么时候需要使用 index.php 页面.例如,如果我的索引页面上只有一个简单的登录页面,它也很可能只是一个简单的 html 页面.对?那我为什么要使用 index.php 而不是 index.html 呢?

However, what I do not understand is that when do i need to use an index.php page. Say for example if i have just a simple login page on my index page, it could very well just be a simple html page as well. Right? Then why would i want to make it index.php instead of index.html?

示例情况的示例会很棒.

An example of a sample situation would be great.

推荐答案

当您希望在文件中执行 php 代码时,您必须选择 PHP 扩展名 (.php).PHP 代码是位于开始 和结束 ?> 标记之间的代码.

You will have to choose the PHP extension (.php) when you want php code to be executed in the file. PHP code is code between the opening <?php or <? and the closing ?> tags.

当不应该执行 PHP 代码时,您可以使用 .html 扩展名.

When no PHP code should be executed you can use the .html extension.

通常,当使用 .php 扩展名时,您会告诉 Web 服务器,它应该使用 php 解释器来处理文件,然后才能将文件传送到浏览器.然后,php 解释器将用 PHP 代码的输出替换 <?php?> 之间的所有内容.就像您手动编写一样.处理后的文件将被传送到浏览器.

Usually when using the .php extension you are telling the web server, that it should use a php interpreter to process the file before it will be delivered to the browser. The php interpreter will then replace all content between the <?php and ?> by the output of the PHP code. Just as if you wrote it manually. The processed file will then be delivered to the browser.

但是,使用 .php 扩展名告诉 Web 服务器处理 php 代码是可配置的.如果需要,您也可以使用其他文件扩展名.

However, using the .php extension to tell the web server to process php code is configurable. If you want you can use other file extensions too.

还有一点需要指出.当你只输入 url 路径(没有文件名)时:

There is another thing that should be pointed out. When you only type the url path (without a filename) like :

http://www.myserver.com/

有一个扩展名(文件名)的顺序,网络服务器(apache)搜索索引文档.例如,apache 配置可能包含如下部分:

there is an order of extensions (filenames) which the webserver (apache) searches for an index document. For example an apache config may contain a section like:

<IfModule mod_dir.c>
      DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

表示按照上面的顺序搜索索引文档.这意味着如果您将 index.html 和 index.php 放在同一文件夹中 - 并具有上述配置 - 始终是 index.html 将由服务器提供.

Meaning that the index document is searched in the order above. This means if you place an index.html and a index.php in the same folder - and having the configuration above - always the index.html would be delivered by the server.

这篇关于何时使用 index.php 而不是 index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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