Question

I have a basic question and since I am a noob with php it is difficult to dig through the thousands of questions you already answered...So I ask you for further help, sorry...

I just need to recall header.php into HTML pages. The website structure look like this:

-index.php
-header.php
-style.css
-articles/article1.php
-image/header.jpg

For index.php I used

<?php include 'header.php'; ?>

and everything works fine! The problem arises with pages like article1.php, i.e. for pages that are not in the root. I tried with

<?php include ('http://localhost/phpBB3/header.php'); ?>

because I am working locally rightnow, and 'localhost/phpBB3' is the root) but it does not work. Also I tried with

<?php include ('/header.php'); ?>

or with

<?php include ('../header.php'); ?>

barely understanding the real meaning of all these ./ (I know, I know, shame on me!)

Moreover, the header.php points to both style.css and header.jpg (the latter inside the image folder) and refers to ids and classes defined, of course, in the style.css. I think I may have some problem in their path as well.

How can I put things in order?

Any help is greatly appreciated! Mya

Was it helpful?

Solution

The reason http://localhost/phpBB3/header.php does not work is because PHP's include requires a local path. You can achieve what you want with dirname( __FILE__ ).

include dirname( __FILE__ ) . '/../header.php';

More on dirname()

More on __FILE__

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top