user2408368
user2408368

Reputation:

php include from main folder to a file in different folder

in my root folder of my domain i have files header.php and footer.php, i have created a new folder and file in the new folder and wanted to include the header and footer files from main. So the paths are: main folder: example.com/header.php new file: example.com/folder/new_file.php <- in this file i want to include the header.

I have tried:

<?php include "header.php"; ?>
<?php include "/header.php"; ?>
<?php include "./header.php"; ?>
<?php include "../header.php"; ?>

and none of them work. Any help would be appreciated thanks.

Upvotes: 0

Views: 131

Answers (3)

user2408368
user2408368

Reputation:

Thanks for all of your support. To answer my question thanks to all here are the answers.

<?php include( $_SERVER['DOCUMENT_ROOT'] . '/header.php' ); ?>

and php include "../header.php";

DO work and i was able to include a file from main directory so thanks to david and code360.

second part of why the css file was not being read is because i had it like this in header.php file:

<link rel="stylesheet" href="css/bootstrap.css">

and missed the first "/"

Thanks again to code360

Upvotes: 0

Craftein
Craftein

Reputation: 762

include_once dirname(__DIR__).'/header.php';

This should work.

Upvotes: 0

Ferrakkem Bhuiyan
Ferrakkem Bhuiyan

Reputation: 2783

<?php include( $_SERVER['DOCUMENT_ROOT'] . '/header.php' ); ?>

it's will work .try may be its help in any of your files

Upvotes: 1

Related Questions