Katie
Katie

Reputation: 327

PHP: include function doesn't work

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!

Upvotes: 2

Views: 7432

Answers (2)

Gaurav Agrawal
Gaurav Agrawal

Reputation: 101

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.).

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382656

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.

Upvotes: 3

Related Questions