Answer the question
In order to leave comments, you need to log in
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>
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question