0

I am vague at understanding the include paths and how they are written out, I know how to set them within the ini file and how to functionally do it set_include_path just not how to get it to be exact each time no matter what.

So I have an admin autoload file that I include in all my headers to register the spl_autoload_register function. I just keep getting errors in my error_log file. It says that

PHP Fatal error:  Class 'Configurate' not found in 
/home/~username~/public_html/testing_ini.php on line 5

So what I am looking for is how can I set the include path to always be the directory before the public_html directory no matter where I am?

I've tried setting the include path to such

.:/opt/alt/php5/usr/share/pear:/opt/alt/php5/usr/share/phphome/~username~/classes/Configurate.php

But I still get the error. Any help and some tips to understanding this entire thing? I suck at relative paths

As per requested spl_autoload_register function

<?php
$ini = parse_ini_file("configurations.ini",true);
foreach($ini as $section) {
    foreach($section as $key=>$value )  {
        define("__".strtoupper($key)."__",$value);
    }
}

//if(__USERNAME__ == null) {
//  header("Location: /setup.php?step=1");
//  exit();
//}
spl_autoload_register(function($class) {
    try {
        if(!file_exists("../classes/{$class}.php")){
            throw new Exception("/classes/{$class}.php does not exist error on line ". __LINE__." in file ". realpath(__FILE__));
        } else
            require_once "../classes/{$class}.php";
    } catch (Exception $ex) {
        echo $ex->getMessage()."<br>";
        echo $ex->getCode();
    }
});
EasyBB
  • 6,176
  • 9
  • 47
  • 77
  • Can you show your `spl_autoload_register` function? – Darren Apr 13 '15 at 02:48
  • check this http://stackoverflow.com/questions/2370053/how-to-include-file-outside-document-root – Deadooshka Apr 13 '15 at 05:00
  • You shouldn't use relative paths when including files. Always use absolute paths. Try this: `getcwd() . '/classes/{$class}.php'` – Darren Apr 13 '15 at 05:31
  • Thanks guys I'll check it out not near the computer right now just phone. – EasyBB Apr 13 '15 at 18:14
  • @Darren that does not work that still sets me in `....../public_html/classes/Configurate.php` which is not what I want – EasyBB Apr 13 '15 at 23:24
  • `/opt/alt/php5/usr/share/phphome/~username~/classes/Configurate.php` is obviously not a path, but a `.php` FILE. Try replacing it with `/opt/alt/php5/usr/share/phphome/~username~/classes/` –  Apr 14 '15 at 18:22

1 Answers1

0

getcwd() and many other methods did not work for me. Though I did find this one method that works great for me in any directory.

set_include_path(
                  dirname( $_SERVER["DOCUMENT_ROOT"] )
                );

Hope this helps anyone else out there looking to get outside the document root and using it like I do.

EasyBB
  • 6,176
  • 9
  • 47
  • 77