Question: Background
==========

I am working on a website, which runs on an Apache server on Windows (at least at the moment). My website directories consist of HTML and PHP files. The idea is to have accessible webpages as HTML files, and whenever I need to use dynamic content, I will use Javascript and AJAX requests in order to request what I need from the server. AJAX requests will be made to PHP scripts, which have a directory dedicated to them. Because I would like to keep everything well organised in their own units, this is the way I do it (I try to avoid inline PHP as much as possible).

Objective
=========

Public HTML files do not need any special settings. When it comes to administrator specific HTML files, however, I would like to do something very specific with them. Instead of writing some inline PHP code to authenticate a user as an administrator on an administrator webpage (an HTML file), I would like to execute authentication script whenever a user tries to open administrator specific HTML files, to check, if the user can open the file.

Question
========

In short, this is my question: *how can I run a PHP script when opening HTML files?* What kind of configurations do I need to do on the Apache server or can I simply utilize PHP somehow?

Answer: 
You can try with an `iframe` / `embed` tag,

OR:

```
<html>

<head>
    <script src="js/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
            $.ajax({
                url: 'php_File_with_php_code.php',
                type: 'GET', 
                data: 'parameter=some_parameter',
                success: function(data) {
                    $('#thisdiv').html(data);
                }
            });
        });
    </script>
</head>

<body>
    <div id="thisdiv"></div>
</body>

</html>

```

Source: [How to run a php script inside a html file?](https://stackoverflow.com/questions/22853669/how-to-run-a-php-script-inside-a-html-file)
You may simply configure your Server (APACHE) to treat Files with .html extension as regular PHP Files.
Here is how: if you don't have a .htaccess File in your Project root, create it.
Then inside the .htaccess File add the following line:

```
    # TELLS APACHE TO HANDLE ALL FILES WITH .html or .htm EXTENSIONS AS PHP FILES.
    AddHandler x-httpd-php .html .htm

```

However, depending on your Server, the above may not work; in which case you may may try one of the following:

```
    # TELLS APACHE TO HANDLE ALL FILES WITH .html or .htm EXTENSIONS AS PHP FILES.
    AddHandler php-script .php .html .htm

```

or this:

```
    # TELLS APACHE TO HANDLE ALL FILES WITH .html or .htm EXTENSIONS AS PHP FILES.
    AddType application/x-httpd-php .htm
    AddType application/x-httpd-php .html

```

However, the first variant may most likely work for you. I hope this helps. Good Luck to you, my Friend.