path issue

i have a database class that require_once a config file like so:  require_once  'configs/configs.php';

all works until i require that class from a vertain folder, then the require inside the class doesn't work and i get:
<b>Warning</b>:  require_once(configs/configs.php): failed to open stream: No such file or directory

any idea?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Without a leading slash, you'll get a relative path (relative to the folder your calling script is in).

Add a leading slash and you'll get an absolute path, always starting at the root. You probably need to add the leading slash:


This will always load it from the /configs folder.
derridaAuthor Commented:
still get the same result.
i need that whereever i call the databse class the configs will work. now it work from some places and doesn't work on others.
Chris StanyonWebDevCommented:
If you want it to work from wherever you call it then you will need to use an absolute path, and not a relative one. a relative path is always 'relative' the the script you're calling from. An absolute path is the same, no matter where you call it from.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

derridaAuthor Commented:
that's what i'm trying to do now and fail. how do i set an absolute path to the configs file in the database class? i have played with realpath but doesn't work.

i have a classes folder and the class is in there. i have a configs folder and the configs file is there. both the classes and the configs folders are in the root folder.
Chris StanyonWebDevCommented:
Ahh. Sorry - my mistake. You need to include the document root in the include path:

require_once($_SERVER['DOCUMENT_ROOT'] . '/configs/configs.php');

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
derridaAuthor Commented:
saved my life thanks :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.