Forum Moderators: coopster

Message Too Old, No Replies

include files

         

bleak26

12:58 pm on Jul 20, 2006 (gmt 0)

10+ Year Member



Hi im trying to create a file which will contain various peices of configuration information for my site.

require ('http://'.$_SERVER['SERVER_NAME'].'/allincludes.php');

I am using require to include a file called allincludes.php, In which i have made some variables. I would like the variables to be available on any page that i require allincludes.php into.

//contents of allincludes.php
$images = "/images/big";

My problem is that when i echo one of my variables defined in the allincludes.php i get nothing as if the variable has not been defined.

eelixduppy

1:01 pm on Jul 20, 2006 (gmt 0)



Try adding error_reporting [us2.php.net](E_ALL); to the top of the script that you are including allincludes.php. Reply with any errors found.

whoisgregg

4:00 pm on Jul 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The way to include a php file is to use the absolute path to the file on the server, not a URL:

include($_SERVER['DOCUMENT_ROOT']."/allincludes.php");

$_SERVER['DOCUMENT_ROOT'] is automatically populated with the absolute path to the root of the web directory. (Something like '/var/www/htdocs/')

eelixduppy

5:42 pm on Jul 20, 2006 (gmt 0)




If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Appendix M for a list of protocols) instead of a local pathname.

[us2.php.net...]

Just thought I'd let you know, whoisgregg. However the problem may be that URL fopen wrappers [us2.php.net] aren't enabled, in which case you will have to use the method described by whoisgregg or enable them.

whoisgregg

5:49 pm on Jul 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, I realize that... but those php files that one grabs will be parsed by their server before they are included.

In bleak26's case, it sounds like there is a file with a bunch of variables defined, but nothing echo'ed. So, including that file through a URL is the same as including an empty file where using the local absolute path will keep those variables defined for use in the script doing the including.

eelixduppy

5:52 pm on Jul 20, 2006 (gmt 0)



>> but those php files that one grabs will be parsed by their server before they are included.

ahh, yes. silly me ;)