php noob question includes etc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheMadHatter
Forum Newbie
Posts: 1
Joined: Tue Apr 27, 2010 4:14 pm

php noob question includes etc

Post by TheMadHatter »

Hey guys i was coding an object orientated login (in php) and came across a problem i havnt seen before haha ok basically im having problems including files here is my folder structure:


_classes
images
includes
member
scripts
stylesheets

ok everything works perfect! except when the login page redirects the verified user to member i am getting include errors because my files are needed by the classes etc in the root.

is there away to combat this in php for example if such and such a page requests me (meaning the needed include) then my directory should be ../includes/db_settings.php

sorry if this makes no sense but hope someone can help!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php noob question includes etc

Post by requinix »

Use absolute paths. $_SERVER["DOCUMENT_ROOT"] will get you to the web root - simply add a path from there.

Code: Select all

include $_SERVER["DOCUMENT_ROOT"] . "/includes/db_settings.php";
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php noob question includes etc

Post by Christopher »

Use absolute paths. Have the base path in your configuration data and concat the file name you want to include to the base path.
(#10850)
Post Reply