Re: $_COOKIE and include() or require()

From: Date: Mon, 23 Dec 2002 08:46:32 +0000
Subject: Re: $_COOKIE and include() or require()
Groups: php.general 
Request: Send a blank email to php-general+get-129154@lists.php.net to get a copy of this message
That doesn't seem to work. This might be because my require tags also send variables (e.g. common.php?variable=1)--would this make a call to a non-PHP extention file fail? What happens is that the calls seem to produce no output (but they don't fail). In other words, require() returns true, but the data that I wanted common.php to display doesn't end up being displayed. As to whether common.inc was able to actually receive the cookies, I haven't the foggiest idea, and there's no way to tell if I can't get it to output anything. Thanks, Luke Chris Wesley wrote:
On Mon, 23 Dec 2002, Luke Sneeringer wrote:
However, then in the script I have a require tag (essentially like require('http://www.mydomain.com/common.php')) line. I call this line, and within that file (same domain) the $_COOKIE[] array as well as variables such as $cookiename are all blank. I cannot figure out for the life of me why this is occuring.
The most likely scenario is that common.php is being processed by the web server & PHP before being included into your code. This would be causing a second HTTP request from your web server to your web server for the included code ... there are no cookies on the HTTP request for the included code, /and/ the variables available to the parent are not available to the included code. You effectivly get the output of common.php, not included code. Try this: - copy common.php to common.inc (or some other extension that your web server is not configured to hand off to be parsed by PHP). - in the parent code, include() the common.inc URL instead of the common.php URL. Let us know if that helps or not. g.luck, ~Chris


« previous php.general (#129154) next »