tags:

views:

45

answers:

2

I not sure what's going on..maybe I missed something simple.

In my connectvars.php file, I connect to the database using the variables in my config.php folder. Here's the hierarchy:

admin(folder)
   config.php
includes(folder)
   connectvars.php
index.php

I want to get information from config.php to use in connectvars.php, so I use: require_once("../admin/config.php");
But everytime I do this I get Warning: require_once(../admin/config.php) [function.require-once]: failed to open stream: No such file or directory in /home/a8879415/public_html/includes/connectvars.php on line 2

BUT when I type: require_once("admin/config.php");, it works.

I thought I had to go up a level, then go down to admin, then get config.php. So how come I just need to go into the admin folder then get config.php?

A: 

They run in the context of the main script, so file references should originate from the main script's directory.

Ignacio Vazquez-Abrams
+1  A: 

Are you running includes/connectvars.php directly or is it included by other file?

I think you are running index.php and every files are included relatively to it's path.

If you want to use relative path to other files, it can be done like that:

require_once( dirname(__FILE__) . '/../admin/config.php' );
dev-null-dweller
index.php is just in my public_html directory(the first level). O that's probably why. But why is everything running relative to the index.php? Is that default?
ggfan