when to use index.php instead of index.html

后端 未结 11 2191
星月不相逢
星月不相逢 2020-12-01 02:58

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 on

相关标签:
11条回答
  • 2020-12-01 03:41

    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

    0 讨论(0)
  • 2020-12-01 03:44

    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.

    0 讨论(0)
  • 2020-12-01 03:44

    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:

    <?php 
         $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.

    0 讨论(0)
  • 2020-12-01 03:49

    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:

    <?php
    $var = 5;
    ?>
    <html>
    <head>
    <title>My Page</title>
    </head>
    <body>
    <h2>Your variable was <?php echo $var; ?></h2>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-01 03:49

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

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

    0 讨论(0)
提交回复
热议问题