index.php about.html,when to use index.php instead of index.html

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.

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.

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

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.

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

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.

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.

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

http://www.myserver.com/

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:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

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.

# Answer 2

It will not hurt a website if you serve every page as .php. Apache is very fast to serve any php, let alone one which contains only static html.

As a beginner you may find php will benefit you, by allowing you to creating simple templates. Site header and footer includes for instance could be written in one file, then included in all the other pages.

# Answer 3

You can use which-ever you prefer:

If you prefer keeping forms and basic pages that don't use data in HTML,

and keep pages that use php in php format that is fine.

But one method I and I assume most others use is just make all of your pages php files. This is because you can include a html document in the php file and display it just the same. But you cannot do php queries from a html file so it is easy to just always use php just incase you want to add some php scripts to it.

Index.php:

$var = 5;

?>

My Page

Your variable was <?php echo $var; ?>

# Answer 4

By default, the apache server needs a file with .php extension to parse the PHP code inside it. Though, if you wish, you may configure your server, by adding a single line to the configuration file, to use files with any extension with PHP code inside it. You can edit the apache by yourself to support php also in .HTML extension.

# Answer 5

Its not a big deal whether you use index.php or index.html. You ca use anyone of either. Only thing is you need PHP(or any other server side scripting language) to make your site dynamic.

Like you have a login page,you can surely make it as inde.html but your logics would either have to be in a different file or embedded in HTMl.

# Answer 6

In simple terms, you can easily access index.html file and get the data beneath it.But index.php is difficult to access. For your simple application index.html will do the trick. If you are planning for some big and secure application go for index.php

# Answer 7

It is beacuse sometimes you may have some logic written on index.php. Like you may check if user is logged in or not and then redirect user to some specific page. Also you may do device based redirection as in case of mobile devices.

You can always choose to create index.html but you do not know when youy may need to have some logic there.

# Answer 8

I also have the same problem mate. But, I think .php is much better than .html since it is more dynamic plus you can do a bunch of cool stuff also.

# Answer 9

For example, in my index.php or another main page I mainly use php because I use variables w/ them in the rest of my site:

$sitepath="http://www.example.com/public";

$author="your name here";

?>

Because I <?php echo $sitepath ?> every time I link an image in my website so it doesn't break or something. Since I'm reusing the name all the time, I use .php to be able to have that service, because if I use the name, I can change it globally.

I think that simple pages like 404.html, aboutus.html, or ViewOneBlogPost.html could be an HTML page, you might not need any functionality/variables for that.

# Answer 10

To check current settings for file extension priority in apache2 with linux

/etc/apache2/mods-enabled/dir.conf

# 高校智慧校园解决方案摘要 智慧校园解决方案是针对高校信息化建设的核心工程,旨在通过物联网技术实现数字化校园的智能化升级。该方案通过融合计算机技术、网络通信技术、数据库技术和IC卡识别技术,初步实现了校园一卡通系统,进而通过人脸识别技术实现了更精准的校园安全管理、生活管理、教务管理和资源管理。 方案包括多个管理系统:智慧校园管理平台、一卡通卡务管理系统、一卡通人脸库管理平台、智能人脸识别消费管理系统、疫情防控管理系统、人脸识别无感识别管理系统、会议签到管理系统、人脸识别通道管理系统和图书馆对接管理系统。这些系统共同构成了智慧校园的信息化基础,通过统一数据库和操作平台,实现了数据共享和信息一致性。 智能人脸识别消费管理系统通过人脸识别终端,在无需接触的情况下快速完成消费支付过程,提升了校园服务效率。疫情防控管理系统利用热成像测温技术、视频智能分析等手段,实现了对校园人员体温监测和疫情信息实时上报,提高了校园公共卫生事件的预防和控制能力。 会议签到管理系统和人脸识别通道管理系统均基于人脸识别技术,实现了会议的快速签到和图书馆等场所的高效通行管理。与图书馆对接管理系统实现了一卡通系统与图书馆管理系统的无缝集成,提升了图书借阅的便捷性。 总体而言,该智慧校园解决方案通过集成的信息化管理系统,提升了校园管理的智能化水平,优化了校园生活体验,增强了校园安全,并提高了教学和科研的效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值