1

I have xampp and I have a project that extensions are *. html and php code have my localhost php does not interpret the code and displays it as php, but I want to run as php code ex: index.html

 <?php
      $seccion='inicio';
      require_once("idiomas.html");
      require_once("configurador.html");
      require_once("header_scripts_css.html");
    ?>

    <body class="clearfix">
      <header id="header">
        <?php require_once("header.html"); ?>
      </header>
      <?php require_once("slider.html"); ?>
      <div id="centro">
        <?php require_once("central.html");?>
      </div>
      <?php require_once("footer.html"); ?>
Cazs
  • 524
  • 1
  • 7
  • 22
  • You can't run PHP in a .html file. – Rimble Mar 21 '14 at 15:33
  • @TomKriek Yes you can. PHP will process any file you ask it to if you look in the right place. – George Mar 21 '14 at 15:33
  • @TomKriek: You can if you tell the server to process `.html` files via PHP. – Rocket Hazmat Mar 21 '14 at 15:33
  • why don't you just change the file extensions to *.php ? – Don Mar 21 '14 at 15:35
  • @Tim Cooper tried this but not working in htaccess think it has to do with httpd.conf and mime.types files – Cazs Mar 21 '14 at 15:36
  • http://stackoverflow.com/questions/18951890/how-to-implement-php-in-html-file?rq=1 or http://stackoverflow.com/questions/5532843/how-to-parse-php-syntax-in-a-html-file-on-server?rq=1 or http://stackoverflow.com/questions/11312316/how-do-i-add-php-code-to-html-files – Justin E Mar 21 '14 at 15:46

1 Answers1

4

you can add

AddType application/x-httpd-php .html

into your .htaccess file or you can modify apache mod-php5 setting

iamsleepy
  • 530
  • 3
  • 7
  • 1
    If adding to htaccess the op needs to ensure he has his allowoverride set appropriately. It may best for security just to change it in httpd.conf or apache2.conf depending on your distro. – Justin E Mar 21 '14 at 15:40
  • don't work variables reads as html code includes etc. .. – Cazs Mar 21 '14 at 15:41
  • You will still need to include the proper php tags, and after changing your configuration make sure you restart your apache. – Justin E Mar 21 '14 at 15:41
  • yes my apache has restarted – Cazs Mar 21 '14 at 15:43
  • I use this method to configure .ptr extensions with my domain, and it works perfectly. Please post more of your apache configuration and maybe we can help you. – Justin E Mar 21 '14 at 15:44
  • 1
    couldn't agree more Justin E. It is better to add into the FilesMatch block in the config – iamsleepy Mar 21 '14 at 15:47
  • It is a clean install of xampp, the latest version – Cazs Mar 21 '14 at 15:48
  • This: AddType application/x-httpd-php .html works, but you need the PHP tags in your html file your html content – Danny Mar 21 '14 at 15:49
  • that is uploaded to a domain, it works fine as you can see does not give any error variables, but in my localhost does not load, and all the php code in html code shown http://1080lol.com/newPanorama/index.php (index.php is a php but, all files include has html extension – Cazs Mar 21 '14 at 15:50
  • Please post your xampp configuration file. Use pastebin. Maybe then you can actually get somewhere. – Justin E Mar 21 '14 at 15:53
  • Did you allow override ? – iamsleepy Mar 21 '14 at 15:55