• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1409
  • Last Modified:

using SITE_ROOT

hello I'm trying to use the php built in SITE_ROOT to set up my path linking and get the following error:

Warning: require_once(\Hosting\4761148\html\gallery\includes\config.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\4761148\html\gallery\includes\int.php on line 18

I'm on shared hosting with GoDaddy.

The config.php file is in the same folder as the int.php file so why doesn't it see it?

my site is set up as:
html/
  gallery/
     includes/
         config.php
         int.php

below is my code for the int.php file:
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);


defined('SITE_ROOT') ? null :
	define('SITE_ROOT', DS.'Hosting'.DS.'4760048'.DS.'html'.DS.'gallery');


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


require_once(LIB_PATH.DS."config.php");

Open in new window

0
vicomin
Asked:
vicomin
  • 9
  • 7
1 Solution
 
meno19Commented:
It might be something with how you used the required once. You started it with "\Hosting" Your syntax might be off a bit. Try this below, also just direct it to the config from the root of the HTML folder.

require_once('gallery\includes\config.php');
0
 
vicominAuthor Commented:
okay this works but it doesn't make use fo the LIB_PATH.DS

//require_once(LIB_PATH.DS."config.php");
require_once('config.php'); //******** works fine

now it fails here:

require_once(LIB_PATH.DS."functions.php");


I changed the SITE_ROOT to:
defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'gallery');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');



0
 
meno19Commented:
Okay try this. I think it does not like how the SITE_ROOT is getting called.

defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'gallery');
defined('LIB_PATH') ? null : define('LIB_PATH', 'SITE_ROOT',DS.'includes');
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
vicominAuthor Commented:
i believe that helped some. however, i still get an error. in the includes folder i have the following files:
config.php
int.php
user.php
db.php
ses.php

on the int.php file I am trying to load them as: config, ses, db then user.

on the user file i have: require_once(LIB_PATH.DS."database.php");

I get the following error:

Warning: require_once(\gallery\includes\database.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\4761148\html\gallery\includes\user.php on line 2

Fatal error: require_once() [function.require]: Failed opening required '\gallery\includes\database.php' (include_path='.;C:\php5\pear') in D:\Hosting\4761148\html\gallery\includes\user.php on line 2

line 2 on user is:
require_once(LIB_PATH.DS."database.php");


if i comment it out it works fine. I'm using the same line of code on the database.php file to include the config.php file.
require_once(LIB_PATH.DS."config.php");

so why does it fail?

0
 
meno19Commented:
It looks like it's trying to find the database.php file as from the files you listed in the include folder database.php does not exist. Where does the database.php file exist?
0
 
vicominAuthor Commented:
it is in the same folder - right next to it

so i reviewed the int.php file and did the following:

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

require_once(LIB_PATH.DS.'config.php');


Error now:
Warning: require_once(\gallery\includes\config.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\4761148\html\gallery\includes\int.php on line 11

Fatal error: require_once() [function.require]: Failed opening required '\gallery\includes\config.php' (include_path='.;C:\php5\pear') in D:\Hosting\4761148\html\photo-gallery\includes\int.php on line 11

line 11 is:
require_once(LIB_PATH.DS.'config.php');

0
 
vicominAuthor Commented:
i'm confused - why can't it find a file next to it?
is the DIRECTORY_SEPARATOR not working right?
0
 
meno19Commented:
Your Directory Separator is working fine but when your calling the files it cannot find them from where you are calling them from. This site root function does not seem to be working, it does seem to be working just as a variable though.

The below code wont work cause you are telling the int.php file that the config.php file is within the \gallery\includes\ folder from within the includes folder. When the config folder is not within anything its in the same folder so the code should just be require_once('config.php');



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

require_once(LIB_PATH.DS.'config.php');
0
 
vicominAuthor Commented:
I'm bad with pathes - get me all the time.

defined('SITE_ROOT') ? null : define('SITE_ROOT', DS.'photo-gallery');

should be operating as such:
if siteroot is null then define it as such:
echo SITE_ROOT; \\ prints  \gallery

echo LIB_PATH; // \gallery\includes
echo LIB_PATH.DS; // \gallery\includes\
echo LIB_PATH.DS.'config.php'; // \gallery\includes\\gallery\includes\config.php

that's an issue.

I'm using a file at: http://www.site.com/gallery/public/admin/index.php
the index file is:
<?php
require_once("../../includes/initialize.php");




0
 
meno19Commented:
It looks as if you just need to fix the paths that you are calling. Are you still having the problem.
0
 
vicominAuthor Commented:
yes - it is killing me
0
 
meno19Commented:
Okay which parts are you getting errors on. I can help but list out the places where you are getting errors. In the initialize.php doc change this line

require_once(LIB_PATH.DS.'config.php');

to

require_once('config.php');
0
 
vicominAuthor Commented:
thanks

i did that on the int page for:

require_once('config.php');

require_once('functions.php');

require_once('session.php');
require_once('database.php');

require_once('user.php');
0
 
vicominAuthor Commented:
i did the same changes to the following files:

database.php
//require_once(LIB_PATH.DS."config.php");
require_once('config.php');

user.php
//require_once(LIB_PATH.DS.'database.php');
require_once('database.php');


I am calling everything from the admin/login.php page
<?php
require_once("../../includes/initialize.php");

this loads just fine
0
 
vicominAuthor Commented:
when I log in I'm directed to the admin/index.php page

which looks like this:
<?php
require_once("../../includes/initialize.php");
if (!$session->is_logged_in()) { redirect_to("login.php"); }
include_layout_template('admin_header.php');
?>
Menu            
</div>
 <p>
          <?php
include_layout_template('admin_footer.php');
?>

the include_layout_template is a function in the functions.php file that is two levels up

function include_layout_template($template="")
{
      include(SITE_ROOT.DS.'public'.DS.'layouts'.DS.$template);
}

it blows up here on the index.php file when making this call to load the header include

0
 
meno19Commented:
I gotta say I think your includes are way more complicated then they need to be. I get what you are trying to do but I do agree it is confusing. To debug this you need to see what is being returned with the function include_layout_template($template=""). Echo this and lets see what string is returned. From their we just need to rewrite it so that it is point to the correct directory. I think that it is just point to the wrong place.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now