Skip to main content
July 28, 2010
Question

Help with PHP Includes on localhost

  • July 28, 2010
  • 1 reply
  • 2018 views

Hi,

I have a very simple index.html file with a header div.  I have put an include into it like this:

    <div class="header">
      <?php include("includes/header.php"); ?>
    </div><!-- end .header -->
I have follwed David Powers setup_php to link to my localhost, putting the whole developement web in c:\websites\localhost\crown.

The actual header.php is in a subdirectory of crown called includes.

When I publish the site to a live server it works perfectly but not on locahost or in liveview.

I don't get any errors, just an empty header bar on the page..  I do get a warning across the top of the screen that I haven't installed flash(which I have)

I believe php is working OK on my localhost as running the php file direct in both liveview and F12 works OK.

BTW, I'm running CS5 on 64bit Win7 home premium.  I've installed Apache 2.2.15 and php 5.2.14.

Any pointers greatly appreciated as I'm quite new to this.

Thanks,

Tim

This topic has been closed for replies.

1 reply

Participant
July 28, 2010

Probably you should start to change your index.html into index.php otherwise your php code will not work.

Best regards

July 29, 2010

Yes, changing index.html to index.php works, but it then means I have to change all my html to php.

As the PHP Includes already work properly on the live server it must be something in my setup that's stopping it working on localhost and liveview.  I can't have to have 2 versions of the website, 1 for live and 1 for test, that sort of defeats the idea doesn't it?

Participating Frequently
July 29, 2010

It surprises me dat php might work in a page that doesn't have the extension .php

I was under the strong impression that php code only works in a .php page.

Good luck.


You can run php on an HTML page, even if it has .htm extensions.

You can make this work by adding the following to your .htaccess file:

AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm

This will then have PHP interpret your .html and .htm pages.