Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.