0

I have a web server that we use, apache, centos5, php

I have a file called 'include.php' that I need to include in multiple sites.

Eg. I have a site called testsite.co.za, now in the index.php i want to include the include.php file, the include.php is not in the root of testsite.co.za,

Now i created another folder includes in the web root directory which contains include.php

my code looks as follows in testsite.co.za/index.php

require_once '../includes/include.php';  

if i run testsite.co.za it can't detect include.php. Is there a certain server setting I need to change in order to include this file?

My directory structureof

-/var/www/html
  -testsite.co.za
      -index.php   
  -includes
      -include.php

Hope this makes sence

3 Answers 3

3

Keep in mind that when using require '../[something]', you're referring to the working directory of PHP, not the path of the actual script. I prefer to always use

require(dirname(__FILE__).'/path');

This way, I know I am requiring a file relative to the file that the require statement is in

So in that case, your include would be:

require_once( dirname(__FILE__).'/../includes/include.php');
2

This was asked long ago, but for anyone finding it via google, the correct answer is to make sure this file is in the PHP include_path that is set in the php.ini OR add your path to the php include_path via the php.ini or at runtime via set_include_path() php function [ http://php.net/manual/en/function.set-include-path.php ]

You file can then be accessed via include('myfile.php') or require('myfile.php') that both search the PHP include_path as well as the current directory for the file to be included.

You might also look into __autoload() in php 5.2 or lower or SplAutoloadRegister() in php 5.3 and 5.4 to have create functions to autoload your classes from files based on how you want via creating that magic function or in the latter case registering a autoload function.

Hope this will help someone along the way.

0

Makes perfect sense.

Well, far as I can see it should work: I use similar directives all the time. I'd check all the directory permissions and ownership, and the file permissions, and if those are all right, I'd check for a rogue .htaccess file or some other piece of lock-downery that may be tripping you up.

If Apache's document root is /var/www/html, then you shouldn't have any trouble pointing at something in /var/www/html/includes/ unless there is some specific directive (or permission issue) blocking it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .