-5

I am not understanding when my main website page should be index.php and not index.html and what's the difference between the two.

And in case if it's index.php, how to manage with the javascipt code.

Thank you.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • `index.php` is exactly the same as `index.html` with one exception - `index.php` can also run php code *(which is placed between `` tags)*. There are some useful little things that PHP can do, such as using `include()` functions, that almost anyone could use, whether they connect to a database or not. Bottom line: they are virtually the same. Use whichever one you wish. – cssyphus Mar 04 '19 at 23:09

2 Answers2

0

my main website page should be index.php and not index.html

In a simple web server configuration, if you request a URL which maps onto a directory, then the server will look inside that for an index document.

It will do this by comparing the files in the directory to a list of possible index document names which often include index.html and index.php.

It checks them in the order of its list and stops when it finds a match.


Adjacent to this, such servers are typically configured to serve .html files as static files and to execute .php files as PHP and serve the result.


And in case if it's index.php how to manage with the javascipt code.

Generating HTML from PHP instead of a static file has absolutely no bearing on how client-side JavaScript is managed.

If you're talking about server-side JS, then you probably don't want to be using PHP at all.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

index.extension is the main trigger file which can be .html, .php or other extensions.

in case of server end programming or you are using PHP language then trigger file should be index.php while for only html content you can go with index.html

Regarding, adding javascript in index.php file, it could be like

<?php 
  echo "I am here in PHP code";
  ?>
  <script>
    alert("I am here in javascript");
    console.log("here in console");
  </script>
  <?php
  echo "I am here ending code";
?>
Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30