Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why when I put this online the php content is being ignored when having the page index.html, while when I save the page as index.php the php content is displayed.

index.html
XML
<html>
<body>

<h1>Welcome to my home page.</h1>
<?php include 'vars.php';
echo "I have a $color $car"; // I have a red BMW
?>

</body>
</html>


vars.php
PHP
<?php
$color='red';
$car='BMW';
?>
Posted

If you name a file with .html then the server is not going to parse any code pieces. When it sees one with .php it will know that it needs to look for php code.

Basically it's the same as when you double-click on an .xlsx file. The computer knows to open it with Excel.
 
Share this answer
 
Comments
Killzone DeathMan 6-Jan-14 9:18am    
Good answer :)
The extension tells the server side (web server) to which handler to pass the file.
HTML extension will go to the basic html handler, but files with PHP extension will be passes to an other handler that can process PHP commands.
If your html file contains PHP blocks the basic handler will ignore them as he does not understand it...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900