$DOCUMENT_ROOT question

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
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

$DOCUMENT_ROOT question

Post by siefkencp »

I get this error any time I'm trying to use the constant $DOCUMENT_ROOT in an include statment as part of my class. Can any one give me some insight it could be something PHP just wont do...

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in class.php on line 22

Code: Select all

class base {
	
public function template_header() {
	include $DOCUMENT_ROOT . '/template/header.php';
	}
}
It maybe that you cant call an include from inside a class I'm just not sure.

Thanks in advance!
Last edited by siefkencp on Fri Jul 21, 2006 1:12 pm, edited 2 times in total.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

inlcude ^^^ spelled wrong & you're missing a quote
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Shouldn't you be using $_SERVER['DOCUMENT_ROOT']? I'm not sure myself but those PHP vars (like $PHP_SELF) I have heard can cause problems. I personally do not use them.
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

Well, that explains some things... :roll:

Anyhow, I still get a failed to open stream error now that I have checked my spellings and path's again...

Thanks
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

Everah wrote:Shouldn't you be using $_SERVER['DOCUMENT_ROOT']? I'm not sure myself but those PHP vars (like $PHP_SELF) I have heard can cause problems. I personally do not use them.
As long as register globals is on the constant $DOCUMENT_ROOT is available to you. (This is an intranet project so extreme security is not as much of a concern.)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is the missing single quote a typo or in the code?
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post by siefkencp »

Typo... I cleaned it up to aviod further confusion.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

try this:

Code: Select all

echo $DOCUMENT_ROOT . '/template/header.php'; // check to make sure it outputs the correct path.
echo getcwd(); // see where you currently are, and investigate the possibility of using relative paths...
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Try putting it in parenthesis?

Code: Select all

include($_SERVER['DOCUMENT_ROOT'].'/template/header.php');
That's how I always do it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

include() is a language construct (I thought) so it doesn't require parantheses. I think the manual says that too.
Post Reply