I am having troubles with require_once() in my application.
So, I have two folders: ‘lib’ and ‘content’. Both are at the same level in the folder structure (i.e. ‘Application’ > ‘lib’ & ‘Application’ > ‘content’).
Under the ‘lib’ folder, I have a couple others:
lib > models
lib > views
lib > variables
Under my ‘content’ folder, I have the pages that are displayed in the browser (add.php, view.php).
On add.php, I have require_once(‘…/lib/views/addClass.php’);. When I run add.php in the browser, I get:
Warning: require_once(./variables/variables.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\application\lib\models\addClass.php on line 2
I can’t figure out why it can’t open the file. Any thoughts?
Relative paths are evil. I personally define the root path of my application as early as I can. That’s probably what’s going on here, check the path that PHP actually used to try to find the file and see if that’s correct.
The funny thing is that I have a variables.php which I define my domain so that I can do something like require_once(DOMAIN . ‘/application/lib/views/add.php’); so I can avoid that but I have to pull in the variables.php file before I can use the constant.
How can I check the path that PHP used? Are you talking about “(include_path=‘.;C:\xampp\php\PEAR’)”?
… to that ini directive, then restart the webservice (Apache?)
However, if you do not have access to your ini file on your LIVE server then you can alter this directive using Apache instructions (in .htaccess say), and even at the page level if you have one single boot file that every public pages is handled by.
[fphp]ini_set[/fphp]
Otherwise you will have to adopt another practice such as having a setting in a config file which contains the actual include path.