Alf
Alf

Reputation: 11

including php document from root

I have PHP pages in diffrent directorys in my root eg.

http://mydomain.com/forum/?action=thread&threadid=9284
http://mydomain.com/library/?s=achievements

I need to include a file on every php document which is in root dir.

include('header.php'); 

does not work

On for example /root/forum/index.php i want to include header.php that is in /root/header.php

which is in /root/

My english is not best but I hope you understand. Thank you.

Upvotes: 1

Views: 115

Answers (2)

Rod
Rod

Reputation: 2066

There are a couple ways to do this:

  • You can add your header into php default include path: set_include_path("/path/to/includes");
    You can make this change permanent by changing your php.ini file.

  • You can create a variable/define which is the common default root folder:

    $path=dirname(__FILE__);
    include($path."header.php");

Upvotes: 5

Anders S
Anders S

Reputation: 249

You could use include '../header.php'.

Upvotes: 0

Related Questions