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

查看:109
本文介绍了何时使用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代码是开头<?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/

有一个扩展名(文件名)的顺序,Web服务器(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放在同一个文件夹中-并且具有上面的配置-始终是索引. 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天全站免登陆