Page 1 of 1

$DOCUMENT_ROOT question

Posted: Fri Jul 21, 2006 12:59 pm
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!

Posted: Fri Jul 21, 2006 1:02 pm
by Luke
inlcude ^^^ spelled wrong & you're missing a quote

Posted: Fri Jul 21, 2006 1:05 pm
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.

Posted: Fri Jul 21, 2006 1:08 pm
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

Posted: Fri Jul 21, 2006 1:11 pm
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.)

Posted: Fri Jul 21, 2006 1:11 pm
by feyd
Is the missing single quote a typo or in the code?

Posted: Fri Jul 21, 2006 1:13 pm
by siefkencp
Typo... I cleaned it up to aviod further confusion.

Posted: Fri Jul 21, 2006 4:03 pm
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...

Posted: Fri Jul 21, 2006 5:38 pm
by pickle
Try putting it in parenthesis?

Code: Select all

include($_SERVER['DOCUMENT_ROOT'].'/template/header.php');
That's how I always do it.

Posted: Fri Jul 21, 2006 7:36 pm
by RobertGonzalez
include() is a language construct (I thought) so it doesn't require parantheses. I think the manual says that too.