[vox-tech] PHP Question: Includes and Variables
Here's the situation. My script, page1.php, calls a script in another directory called config.php via require_once. config.php declares several variables which should be accessible in page1.php. For example: --- http://myphpsite.net/dir1/page1.php ?php require_once(http://myphpsite.net/dir2/config.php;) echo myVariable = $myVariable-daValue; ? --- http://myphpsite.net/dir2/config.php ?php $myVariable-daValue = Hello, World; ? --- So when I execute page1.php, I should get: myVariable = Hello, World But I don't. Instead the variable is undefined. If I put the echo command inside config.php, though, it displays properly. I've confirmed that all permissions and ownerships and all that are the same, and I can't find a configuration value in php.ini which might have something to do with this. It's acting as though $myVariable is only defined within the scope of config.php, but I have no idea why that would be. It makes no sense to me at all. Any suggestions besides taking a large sledgehammer to the server? -- Sláinte, Richard S. Crawford (AIM: Buffalo2K) http://www.mossroot.com http://www.stonegoose.com/catseyeview We live as though the world were how it should be, to show it what it can be. --Angel, Season 4 ep. 1 ___ vox-tech mailing list vox-tech@lists.lugod.org http://lists.lugod.org/mailman/listinfo/vox-tech
Re: [vox-tech] PHP Question: Includes and Variables
On Fri, Feb 25, 2005 at 01:41:31PM -0800, Richard S. Crawford wrote: Here's the situation. My script, page1.php, calls a script in another directory called config.php via require_once. config.php declares several variables which should be accessible in page1.php. For example: Just to make sure, neither the require_once nor the echo are inside your own PHP functions, are they? -bill! (never really used 'require_once'...) ___ vox-tech mailing list vox-tech@lists.lugod.org http://lists.lugod.org/mailman/listinfo/vox-tech
Re: [vox-tech] PHP Question: Includes and Variables
Bill Kendrick said: On Fri, Feb 25, 2005 at 01:41:31PM -0800, Richard S. Crawford wrote: Here's the situation. My script, page1.php, calls a script in another directory called config.php via require_once. config.php declares several variables which should be accessible in page1.php. For example: Just to make sure, neither the require_once nor the echo are inside your own PHP functions, are they? Nope. But I found the problem. Deep in the heart of some of the more obscure documentation on php.net, I found this: Please don't forget: values of included (or required) file variables are NOT available in the local script if the included file resides on a remote server. So even though the include file was on the same server as the main script, I was calling it via a URL, so the PHP processor was looking at it as an HTTP request, so the variables inside the include script were not available to my main script. I changed the require_once call to reference the include file by absolute path instead of by URL, and it works now. -- Sláinte, Richard S. Crawford (AIM: Buffalo2K) http://www.mossroot.com http://www.stonegoose.com/catseyeview We live as though the world were how it should be, to show it what it can be. --Angel, Season 4 ep. 1 ___ vox-tech mailing list vox-tech@lists.lugod.org http://lists.lugod.org/mailman/listinfo/vox-tech
Re: [vox-tech] PHP Question: Includes and Variables
Richard S. Crawford wrote: Here's the situation. My script, page1.php, calls a script in another directory called config.php via require_once. config.php declares several variables which should be accessible in page1.php. For example: --- http://myphpsite.net/dir1/page1.php ?php require_once(http://myphpsite.net/dir2/config.php;) echo myVariable = $myVariable-daValue; ? --- http://myphpsite.net/dir2/config.php ?php $myVariable-daValue = Hello, World; ? --- So when I execute page1.php, I should get: myVariable = Hello, World But I don't. Instead the variable is undefined. If I put the echo command inside config.php, though, it displays properly. I've confirmed that all permissions and ownerships and all that are the same, and I can't find a configuration value in php.ini which might have something to do with this. It's acting as though $myVariable is only defined within the scope of config.php, but I have no idea why that would be. It makes no sense to me at all. Any suggestions besides taking a large sledgehammer to the server? Not certain it's required, but have you ensured that allow_url_fopen is enabled in php.ini? Also, it should *not* be required, but have you tried braces? HTH, -Micah ___ vox-tech mailing list vox-tech@lists.lugod.org http://lists.lugod.org/mailman/listinfo/vox-tech