Intuitisoft
Intuitisoft

Reputation: 1417

Disable PHP script execution on HTML file from a php include

I want to display html file content in php file script without execute any php script from html file. It's for security reason.

Files :  
|_ content 
| |_page.html 
|_page.php

page.php content :

<div>
    <span>
     <?php include('content/page.html'); ?>
    </span>
</div>

page.html content :

    <b>Titre :</b> hello world. 
<?php echo "[php execution]"; ?>

When I open the page.html I see:

Titre : hello world.

when I open the page.php I see:

Titre : hello world.[php execution]

I don't want to execute any php script on the page.html because the user can change the content. I would like to include only the html content and disable all php script execution.

Upvotes: 0

Views: 2033

Answers (1)

Emily Shepherd
Emily Shepherd

Reputation: 1369

include will always exclude PHP code, but you can get round this by reading and echoing the file instead:

<div>
  <span>
    <?php echo file_get_contents('content/page.html'); ?>
  </span>
</div>

Upvotes: 6

Related Questions