0

I have an HTML file that has a rather long navigation menu inside of it. I want to take that menu out of the HTML and place it into an external PHP page and then call it with

<?php include 'navigation.php'; ?> in the HTML file.

I have tried just adding this into the HTML file but it doesn't display anything as well as no errors on the page.

What do I need to do (if it's even possible) to keep the files HTML and use the php require function?

3
  • Did you give the page a .php suffix? Commented Jul 11, 2013 at 22:07
  • The navigation.php has the .php and the index.html has the .html that is the way I really want to keep it. Commented Jul 11, 2013 at 22:08
  • You need a .php extension to serve a php file. You can adjust your Apache settings to do this though Commented Jul 11, 2013 at 22:08

2 Answers 2

2

Add this in in your httpd.conf and then you can process PHP code on HTML pages

AddHandler application/x-httpd-php .php .html
Sign up to request clarification or add additional context in comments.

4 Comments

Is this something that GoDaddy would provide or do I just make a new file with the httpd.conf name and place that code inside of it?
@user2371301 you can use it in a .htaccess file as well, GoDaddy wont give you access to the conf file, I think!
Ok I added an .htaccess file to the project and copied it into but still nothing happens?
@user2371301 cant tell you the problem, try echoing something on a HTML page and see, make sure you are in the same diretory or lower with the htaccess. Im off to bed!
1

Q: Did you give the page a .php suffix? That should be all you need to do.

Remember the way PHP works - you basically "embed" your PHP code in an HTML page, and the server executes the PHP before it serves (the rest of) the HTML.

But in order for PHP to "see" your code, you need to make sure your "HTML page" has a .php suffix.

As a crude workaround, you can add ".html" to the list of file suffixes that PHP will parse.

But this could cause other things to break.

If you want to embed PHP code in your "index.html", the best, cleanest approach is to simply rename it "index.php".

IMHO...

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.