0

On my localhost, I tinker with php.ini to set the include_path. But, overtime the line for the include_path in my php.ini has grown and it looks, ummm, unsightly. I'm looking for a way to set include_path like, I can copy-paste a single include line, say <?php include("superfile.php");?> on all pages, regardless of where they are in the directory tree, where superfile contains all include_path directives.

I've already tried,

<?php
    $include_path = $_SERVER["DOCUMENT_ROOT"] . "/more/directories/as/needed/";
    ini_set("include_path", $include_path);
    include("initialize.php");
?>

and saved it on the root folder as superfile.php. However if I want to set the include path of a file residing at, say root/sub, by way of superfile.php I need to do <?php include("../superfile.php"); ?> (with "directory up" dots), defeating my purpose of setting the include_path.

Any suggestions? Thanks!

skytreader
  • 11,467
  • 7
  • 43
  • 61
  • If your file at root/sub has the include_path set, include 'superfile.php' will work, I don't catch your drift here mate. – Tom Sep 17 '11 at 18:31
  • My bad. I phrased my question badly, sorry. Edited it now to be (hopefully) clearer. – skytreader Sep 17 '11 at 19:24
  • This question has been answered wrongly. **No, it is not possible at all!** You must edit `php.ini` to set `include_path` for all directories. An alternative is placing a `.htaccess` file in all directories as outlined in my answer: http://stackoverflow.com/a/8579545/220060, but a **single** file does not suffice. – nalply Mar 05 '13 at 11:03

1 Answers1

1

It sounds like you've removed all of your custom include_path directives from the php.ini.

To allow all scripts to call <?php include("superfile.php");?> simply add the one entry to your php.ini include_path that will allow this, and your set.

Shad
  • 15,134
  • 2
  • 22
  • 34
  • Errr...no, sorry. Bad tenses and phrasing on my part so my question is, admittedly, vague and unclear. I've edited it and I hope it's clearer now. – skytreader Sep 17 '11 at 19:21
  • 1
    @skytreader `superfile.php` can only have influence over files that include it, and in order to include it, files need to know where it is relative to themselves OR via htaccess/php.ini include_path settings. – Shad Sep 17 '11 at 19:43