2

I'm following a tutorial for creating an instantiate file with the required files. This is the project tree:

enter image description here

and this is my instantiate.php:

defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'var'.DS.'www'.DS.'html'.DS.'photo_gallery');

defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

//load config file first
require_once(LIB_PATH.DS."config.php");

//load basic functions next so that everything after can use them
require_once(LIB_PATH.DS."functions.php");

//load core objects
require_once(LIB_PATH.DS."session.php");
require_once(LIB_PATH.DS."database.php");

//load database-related classes
require_once(LIB_PATH.DS."user.php");

In login.php, I am requiring the initialize file as:

require_once("../../includes/initialize.php");

But following the tutorial, I could use the LIB_PATH in files such as database.php that requires config.php and on user.php requiring database.php.

At the moment, they require the file, without path, as they are located in the same includes file. However, if I've understood all right the way directory separator, site root and lib_path works, it's to improve that, to don't need to add different paths everywhere, just add the path through the constants. Well, it doesn't work! It displays this: (on top you're seeing the echo of the dirname(__FILE__) in the index.php on the public folder.

enter image description here

I've checked the phpinfo to see the root path... and everything seems alright, but not working if I try to use this LIB_PATH.DS.

Last thing I've read about it's some ibay restrictions, but I've tried to do more research and I can't even find what this "ibay" is.

Does anyone knows why this is happening? Thank you!

Federico J.
  • 15,388
  • 6
  • 32
  • 51
eve_mf
  • 795
  • 3
  • 12
  • 36
  • 1
    You say the code there is about `instantiate.php`, but it looks like the real name is `initialize.php`, did you make a mistake, or do you have another file? – Federico J. Nov 06 '15 at 17:38

1 Answers1

1

You're getting a Notice because you're having an error on the path to include your file: You're not getting the initialize.php file loaded on the script. If you really want that file loaded (And you REALLY want it, as your code can't go without it), you should use require instead of include. That way, if the file is not present, you'll get an error message and your code will stop (See that stop as something you really want, as if you don't have the paths your program will miserably fail).

An even more, you should use a require_once, so you don't overload the application you're building: If the file was loaded one time, it won't be loaded again.

You may check if the file is loaded, following the advice of this question: Check if a file was included or loaded

Community
  • 1
  • 1
Federico J.
  • 15,388
  • 6
  • 32
  • 51