简体   繁体   中英

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM