Jump to content

is it possible to set include path to like home/site/public_html/includes?


leefentress

Recommended Posts

I guess I just never learned the best practice for includes and include paths. I've got this silly messy code I'm trying to replace with something simple that works well.

<?php
$mypath01 = '/Includes';
$mypath02 = './Includes';
$mypath03 = '../Includes';
$mypath04 = '../../Includes';
$mypath05 = '../../../Includes';
$mypath06 = '../../../../Includes';
$mypath07 = '.';
$mypath08 = './';
$mypath09 = '../';
$mypath10 = '../../';
$mypath11 = '../../../';
$mypath12 = '../../../../';
set_include_path(get_include_path() . PATH_SEPARATOR . $mypath01 . PATH_SEPARATOR . $mypath02 . PATH_SEPARATOR . $mypath03 . PATH_SEPARATOR . $mypath04 . PATH_SEPARATOR . $mypath05 . PATH_SEPARATOR . $mypath06 . PATH_SEPARATOR . $mypath07 . PATH_SEPARATOR . $mypath08 . PATH_SEPARATOR . $mypath09 . PATH_SEPARATOR . $mypath10 . PATH_SEPARATOR . $mypath11 . PATH_SEPARATOR . $mypath12);
?>

 

I have so many pages nested at different levels in various folders and subfolders, I couldn't figure out an easy way for them all to find the includes they were supposed to be including so I would get errors saying the thing to be included couldn't be found. So then I set up that code to set the include path to look at various levels above itself and what not, and it works, but I don't like it. So then I wondered, is there a way to set more of a static location for it to always know to look to by using like the path from the home directory where in my case it would be like home/galilee/public_html/includes. If that would work, any idea what I could do for my local copy since it doesn't have the same structure with the home/galilee/public_html stuff?

Agreed with lemmin, use $_SERVER['DOCUMENT_ROOT'] before using includes, eg

define('INC', $_SERVER['DOCUMENT_ROOT'] . '/Includes/');

Then when ever you want to include a file from your includes folder, just do

include INC . 'file.php';

 

You do not to to configure your the include_path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.