Rikard
Rikard

Reputation: 7805

php root path assigned to variable

I'm a bit mixed up about php path's. I have a global.php file to assign the root path to a variable so that I can change locally instead of in every file. It looks like this:

$domain_path = $_SERVER['DOCUMENT_ROOT'];

Apparently this gives me a url and include() doesn't like it ( http:// wrapper is disabled in the server configuration by allow_url_include=0 ).

This global.php file is in the website "root/common" and gets included by all files in different directories.

This works if I write in every file:
<?php include $_SERVER['DOCUMENT_ROOT'].'/common/head_info_'.AC_LANG.'.php'; ?>

but this doesn't (and I know global.php was included):
<?php include $domain_path.'/common/head_info_'.AC_LANG.'.php'; ?>.

Q: How can I assign a path to that variable so it works inside each different file?

Upvotes: 0

Views: 320

Answers (1)

Hanky Panky
Hanky Panky

Reputation: 46910

That's a variable Scope problem, is your global variable in same scope?

You can do

$_GLOBALS["domain_path"] = $_SERVER['DOCUMENT_ROOT'];

and use it like

<?php include $_GLOBALS["domain_path"].'/common/head_info_'.AC_LANG.'.php'; ?>

Upvotes: 1

Related Questions