1
<!DOCTYPE html>
<html>
<head>
<?php include('head.php'); ?>
</head>
<body>
-snip-
</body>
</html>

What am I doing wrong? When I open this file (index.html) in a browser it shows a blank page, and nothing in my php file shows. It doesn't recognize the include statement as code.

My php file contains this:

<title>Title here</title>
<link rel="stylesheet" type="text/css" href="main.css">

Feel free to yell at me, as I am a beginner. I tried looking this up and I made sure the syntax is correct.

7
  • 3
    you can use php only in files named *.php not *.html Commented Nov 30, 2013 at 16:42
  • Even after I renamed it to index.php it did not affect anything. Commented Nov 30, 2013 at 16:43
  • Do you got PHP installed? Like XAMPP or something? Commented Nov 30, 2013 at 16:45
  • you cannot open the file directly in the browser. Add the path to the php server (if u can understand what im saying) Commented Nov 30, 2013 at 16:46
  • No, doing so now. I think that's the issue. Commented Nov 30, 2013 at 16:47

4 Answers 4

2

Use index.php not index.html as it is a php function it will not work on html. And you have to run this page in a php server otherwise it will not give result.

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

2 Comments

Oh, I see, maybe the php server is the issue then.
If you are using window you can install wamp server it is easy to install easy to use.
0

First of all your file needs to be in .php extension. Secondly if you are trying this in your local system, you need to set-up a local web server, for this you can use, wamp or XAMPP

Once the local server is ready, you can put your files under the www folder of your local server set-up and view the file in browser by loading,

http://localhost/index.php

or

127.0.0.1/index.php

Comments

0

You need to do 2 things: 1. change index.html to index.php (otherwise the PHP server doesn't process your files) 2. change head.php to echo 'Title here'; echo '';

Comments

0

As you have XAMPP installed you need to be going to http://localhost to run your PHP scripts. Loading your PHP scripts directly into the web browser will not work.

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.