2

I've been out of the web world for a little while, but I'm trying to make a website using HTML5 and PHP. It's a simple html file with a PHP include statement linking to PHP file. This is basically my index.html file:

<!DOCTYPE HTML>
    <html>
    <head>
         <title>Title</title>
         <link rel="stylesheet" href="style.css" />
     </head>
     <body>
                  <?php include("header.php"); ?>
                  TEST
     </body>
     </html>
     </html>

And to keep it simple, let's say header.php just has the following:

 <div class="header">
     Hello
 </div>

So the text in index.html will show up but nothing from header.php. I have PHP5 downloaded, so I don't understand what the problem is. Are there some configuration settings that need to be set before trying to load this local file? Is it something with HTML5? All my PHP projects from college don't load either and they used to locally. Appreciate the help, thanks!

6
  • What does the HTML source code view of the page show? Commented Jun 3, 2012 at 18:56
  • How are you opening that page? Commented Jun 3, 2012 at 18:56
  • What does error_reporting(E_ALL) tells you? Commented Jun 3, 2012 at 18:59
  • possible duplicate of why does this php code not execute? Commented Jun 3, 2012 at 19:03
  • @Pekka: The source code view prints out verbatim what is written in the index file. So it prints out <?php include("header.php"); ?>. Commented Jun 3, 2012 at 19:03

2 Answers 2

3

This is basically my index.html file:

Your file needs to have .php extension not .html unless otherwise specified via settings to serve .html as a php file.

Sign up to request clarification or add additional context in comments.

7 Comments

I've tried changing the index file extension to .php, like you suggest, but that doesn't seem to work either
Should not matter, because the called file is important, not the included.
@Katie: How are you running the file? Do you have WAMP or other server installed? Are you accessing file using http://localhost/..... Is header.php present in same folder where your script is and that you are not making any spelling mistakes. That should work otherwise.
I've been accessing it by file:///. I just tried localhost and nothing shows up now. Ah! I don't have a server installed.
@Katie: That's the issue then :)
|
1

As Sarfraz said you need to save the file as .php not .html, that should work.

I assume you have installed Apache or some webserver along with PHP. If not, better use XAMPP or WAMP.

And do run it as http://localhost/index.php after saving it default web server directory (www, htaaccess, etc.).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.