2

I am trying to call my header.php from project_1.php. That means that I have to go back to my root. I tried with the following, but there is no CSS is called:

<?php include dirname(dirname(__DIR__)).'/resources/includes/header.php'; ?>

The page is in:

root -> projects -> project_1.php

The header is in:

root -> resources -> includes -> header.php

When I call my header from a page there is in:

root -> index.php

the header is working fine. Does anybody knows how I can solve that?

Update after answers: Thank you for all the answers. I have tried the following, but with no result.

The path to the page is:

http://localhost:8888/test/projects/portfolio_single.php

The header is in:

http://localhost:8888/test/resources/includes/header.php

<?php include 'resources/includes/header.php'; ?>
<?php include '../../resources/includes/header.php'; ?>
<?php include dirname(dirname(__DIR__)).'resources/includes/header.php'; ?>
<?php include dirname(dirname(__DIR__)).'../resources/includes/header.php'; ?>
<?php include dirname(dirname(__DIR__)).'../../resources/includes/header.php'; ?>
<?php include( $_SERVER['DOCUMENT_ROOT'] . '/resources/includes/header.php' ); ?>
10
  • 1
    Pretty sure that ../ works in includes. Commented Jul 3, 2016 at 13:35
  • You might be able to use $_SERVER['DOCUMENT_ROOT'] which is a string set to the web root of the current website. Do you get an error when you try to access it? Commented Jul 3, 2016 at 13:41
  • This might be useful: php includes is there any way to include a file relative only to that document? Commented Jul 3, 2016 at 13:46
  • <?php include( $_SERVER['vouzalis'] . '/resources/includes/header.php' ); ?> remove vouzalis and replace with DOCUMENT_ROOT Commented Jul 3, 2016 at 14:14
  • 1
    $_SERVER['DOCUMENT_ROOT'] only takes you to the webroot. So you need to use $_SERVER['DOCUMENT_ROOT'] . '/vouzalis/resources/includes/header.php' Commented Jul 4, 2016 at 2:59

2 Answers 2

1

Try this one

<?php include( $_SERVER['DOCUMENT_ROOT'] . '/resources/includes/header.php' ); ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the answer. I just updated my question. I tried what you wrote, but still not working
0

Try using this code Each time you use "../" you go back once a folder back, so you go to root and then you can go to resources and the folders you need to go to.

include ../../resources/includes/header.php';

1 Comment

Yhank you a lot for your answer. I just updated my question with the things I tried. But it dosent work yet:-/

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.