0

On a tutorial for dynamic page replacing content, the example demo files have php scripts that are supposed to run inside of an .html file

<body>

    <?php include('../header.php'); ?>

how does this work?

Here is a link to the demo: http://css-tricks.com/rethinking-dynamic-page-replacing-content/

my website that I'm implementing this on has file structure like:

index.php
includes/header.html
includes/footer.html

etc.

So I was trying to change my structure to look more like the example index.html includes/header.php

but it doesn't seem to work.

Harrison
  • 430
  • 2
  • 6
  • 13
  • you would have to change the fileassociations so that he interprets the html file as a php file and executes it like that. but the normal way is to make a .php file and to do some rewrite using mod_rewrite (or isapi_rewrite on windows) – ITroubs Mar 20 '13 at 17:10
  • 1
    To make an .html run as a .php, include `AddType application/x-httpd-php5 .html` or `AddType application/x-httpd-php .html` in your `.htaccess` file. Works on most servers. – Funk Forty Niner Mar 20 '13 at 17:13

4 Answers4

0

In order for PHP to run in an HTML file, HTML has to be added as a mime type in an apache config as php.

Most importantly, most pages you see on the web use mod-rewrite to rewrite pages as .html rather than a query.

Ray
  • 894
  • 1
  • 6
  • 23
0

I think that you are trying to use PHP as a template engine to assemble your web pages. If this is the case, you need to be adding the following to index.php:

 <?php include('includes/header.html'); ?>

and similarly for footers and other content areas.

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
0

Is the code you've pasted inside index.php? If so, I think the problem is just that your path to the header.php file is wrong. include('../header.php') looks for header.php in a folder one level above wherever index.php is. I think you want include('includes/header.php') instead.

Liv
  • 260
  • 1
  • 4
0

You have to change/implement the Apache File Handling options and this can be done through two ways:

First Way

  • Step 1: Login to your CPanel by typing www.yourdomain.com/cpanel into your address field in your browser. Type in your login information.
  • Step 2: Click on the Apache Handlers icon or link option.
  • Step 3: Enter in the file extension you want to add like .html into the small field and application/x-httpd-php in the larger field for the PHP program. Then click the Add button. If you want to delete one, select it from the drop-down menu and click the Delete button. The other programs that you might want to have it run thought are below:

application/x-httpd-cgi - for CGI

application/x-httpd-asp - for ASP (Active Server Pages)

application/x-httpd-asp-cgi - for ASP in CGI scripts

application/x-tar - for .tgz compressed files

application/zip - for .zip compressed files

Second Way

.htaccess Method

On a new line paste in the following.

AddHandler application/x-httpd-php .html

AddHandler application/x-httpd-php .htm

Save the file and then upload it back to your site root directory. That’s it. Your files that end in .html or .htm will now be processed by PHP so you can put PHP code in them.

Vineet1982
  • 7,730
  • 4
  • 32
  • 67