Possible Duplicate:
error using include_once with a php variable
My code is like this:
<?php // file location: include/config.php
$CONFIG["DIRECTORY"]["HTMLINC"] = "http://127.0.0.1/mysite/html_include";
?>
,
<?php // file location: ./template.php
require_once("include/config.php");
// ...
require($CONFIG["DIRECTORY"]["HTMLINC"] . "/anotherpage.php"); // Doesn't work
?>
It gives the following warning message:
Warning: require(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in…
I’m currently testing the code in my local server, so I can easily change the value of allow_url_include. But I will eventually upload this code to a remote server. I cannot guaranty that allow_url_include will always be set to 1.
How do I prevent this warning message and make this code work?
that isn’t an absolute path. that is a URL. the absolute path would be the path to the file on disk. If you go to
/var/www/mysite/html_includeto access the file to edit it, that is the absolute path. You would want to set$CONFIG["DIRECTORY"]["HTMLINC"]to that absolute path. You can use$_SERVER['DOCUMENT_ROOT']to get the web root supplied by apache and append the/mysite/html_includeto generate the right path. ideally you would probably have a separate config variable called something like APP_ROOT that is the document root + /mysite (the absolute path to your application). something like:This would allow you to use APP_ROOT for other variables too:
etc.