1

I've been using the php include function for my navbar for my website. It works well but.... My HTML says

<?php include 'include/navbar.html'; ?>

Now if I have a HTML page in /techpages/toptech.html so I would like to change my php include to <?php include 'http://example.com/include/navbar.html'; ?>. The problem is I get heaps of errors then.

Can someone help me? Can someone answer one of these questions?

  1. How can I make the PHP include function work with a full URL?
  2. HTML has ../ to go into the parent folder. Is there a CSS equivilant?

Any help would be much appreciated.

3
  • 1) give it absolute or relative path on your local machine. 2) ../ does not belong to HTML, PHP or any other language; it's a feature of the filesystem. Of course CSS supports it. Commented Jun 1, 2013 at 9:44
  • Some servers have restrictions that disallow including external URLs. Check with your hoster if this applies to you. If you have your own server, check your PHP configuration. What errors exactly do you get? Maybe we can help you more in depth if you post them here. CSS should have the same thing for the parent folder. Does it not work for you? Commented Jun 1, 2013 at 9:45
  • have a look at stackoverflow.com/questions/15161678/… Commented Jun 1, 2013 at 9:56

2 Answers 2

1

Here are two approaches which I think will work for what I imagine you are trying to achieve:

  • You could include via include $_SERVER['DOCUMENT_ROOT'].'/include/navbar.html'; - this will always include the same file regardless of in what file in what directory you put the include
  • PHP has an include_path which specifies where to look for file-includes, you can add the /include directory in this include_path and from there on always include via include 'navbar.html'. But to be able to do this you have to have permission to access/modi the php.ini...
Sign up to request clarification or add additional context in comments.

Comments

0

One of the options of doing that is:

include($_SERVER['DOCUMENT_ROOT']."/include/navbar.php");

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.