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.
To check current settings for file extension priority in apache2 with linux
/etc/apache2/mods-enabled/dir.conf
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.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.
For example, in my
index.php
or another main page I mainly use php because I use variables with them in the rest of my site: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
, orViewOneBlogPost.html
could be an HTML page, you might not need any functionality/variables for that.