I have the following folder structure for my site:
Admin/
Tech/
index.php
classes/
include/
core/
Everything seems to work except for when i try to call the following code from Admin/index.php
<?php
#including our init.php
require '../core/init.php';
$general->logged_in_protect();
?>
I get the following error for some reason. I can't figure out what to do to fix it or if its even possible to fix.
The core/init.php file has the following code:
<?php
#starting the users session
session_start();
require 'include/database.php';
require 'classes/users.php';
require 'classes/general.php';
$users = new Users($db);
$general = new General();
$errors = array();
?>
error that i am receiving:
PHP Warning: require(include/database.php): failed to open stream: No such file or directory in
Can someone please help me with this?
You probably just need:
require '../include/database.php';
require '../classes/users.php';
require '../classes/general.php';
But if you use a lot of relative paths, it can get messy real quickly so you might want to consider using your base-directory like for example (you can also use a variable or a constant for that):
require $_SERVER['DOCUMENT_ROOT'] . '/include/database.php';
require $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php';
require $_SERVER['DOCUMENT_ROOT'] . '/classes/general.php';
If you use paths relative to current script location, like this:
<?php
require(dirname(__FILE__).'/../core/other.inc');
...
?>
You always have it under control, regardless of the include_path
PHP ini setting.
In your case you should have the following:
<?php
#including our init.php
require(dirname(__FILE__).'/core/init.php');
$general->logged_in_protect();
?>
and core/init.php
will look like:
<?php
#starting the users session
session_start();
require(dirname(__FILE__).'/../include/database.php');
require(dirname(__FILE__).'/../classes/users.php');
require(dirname(__FILE__).'/../classes/general.php');
$users = new Users($db);
$general = new General();
$errors = array();
?>
Hope this helps.