L
L
LLEM00N2020-09-27 17:50:10
PHP
LLEM00N, 2020-09-27 17:50:10

What to do if PHP script does not run from HTML file?

Installed XAMPP to write in PHP. Everything works if you run the .php file. But, when I decided to try to write a simple form in html and insert PHP there, I got

FORBIDDEN
You don't have permission to access this resource.

<html>
<body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
        Name: <input type="text" name="name">
        <input type="submit">
    </form>

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") 
        {
        $name = $_REQUEST['name'];
        echo $name
    }
    ?>
</body>
</html>


What to do? Save.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Nikitin, 2020-09-27
@LLEM00N

It is better to use php in files with the php extension, but if, for some reason, it is needed in html files, then you need to make sure that the server settings are correct and mentally prepare Apache for the opportunity to meet php where it does not expect it. Open or create an .htaccess config at the root of your project and add the following statement there:
AddType application/x-httpd-php .html

F
felony13twelve, 2020-09-27
@felony13twelve

PHP script and won't run from html file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question