Re: Include / Require

From: Date: Thu, 05 Apr 2001 20:34:35 +0000
Subject: Re: Include / Require
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-47323@lists.php.net to get a copy of this message
is the file localhost? because the file being localhost or remote makes a huge difference. lets assume its localhost incdex.php <?php $table = 'test'; include_once("$DOCUMENT_ROOT/include/variables.php"); ?> now, variables.php will NOT return variables, thats not what is for. it just includes the code, thats it. variables.php <?php if ($table == 'test') echo "do something..."; else echo "do something else..."; ?> there you. include does NOT return variables. imagine it like this, imagine you opened variables.php in your editor, and cut and paste all that code right exactly where include_once(...) was, thats what php is doing. now include_once("http://somedomain.com/variables.php"); is very very different, this will send and HTTP request for the page, local variables will not be seen by variables.php any variables set in variables.php will not be returened either. include_once("http://somedomain.com/variables.php?table=test"); this will send the variable table to variables.php but variables.php will still not be able to return anything. using include_once(..) this way has limited usfullness. not saying its not usfull, just saying its limited. -- Chris Lee lee@mediawaveonline.com ""Ashley M. Kirchner"" <ashley@pcraft.com> wrote in message news:3ACCB895.C1AEE5F1@pcraft.com... Lindsay Adams wrote: > So, leaving out the table=$table will still result in $table being defined > by the code prior to the include. Actually, the the I'm trying to include has several segments in it, which depend on which table was just queries. It basically looks like this: if (table_1) { return this set of variables } elseif (table_2) { return this other set } elseif (table_3) { return these ones } else { echo "you bonehead, you didn't include a table!"; } You're saying, if I just include 'variables.inc', it will know what $table is (from the main script) and would run through that routine fine? Actually, it makes sense, all it does is include it as if I wrote it in the main script. Okay, so how can I make it so I only get the variables returned, as opposed to it including the whole bit in the main script? (kinda like the way a function() with a return $var in it would work.) AMK4 -- W | | I haven't lost my mind; it's backed up on tape somewhere. |____________________________________________________________________ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130 SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Laboratories, Inc. . eFax 248.671.0909 http://www.pcraft.com . 3550 Arapahoe Ave #6 .................. . . . . Boulder, CO 80303, USA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#47323) next »