RE: [PHP] Strange setcookie problem?
| From: | John W. Holmes | Date: | Tue, 22 Apr 2003 23:47:05 +0000 |
| Subject: | RE: [PHP] Strange setcookie problem? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144921@lists.php.net to get a copy of this message | ||
> I use the following code to set a cookie on a page on my site:
>
> $value = 'some other value';
> setcookie ("mad", $value, time()+3600);
>
> When I test for the existence of cookies on this and other pages via
>
> print_r($_COOKIE);
>
>
> it shows up as existing with the appropriate value -- EXCEPT on my
> site's index page, where I am attempting access it to determine if the
> visitor has opted in to particular content.
>
> Output from print_r on /index.php:
>
> Array ( [member_id] => 1 [pass_hash] =>
3ea2565f212a118e5a808103fea59152
> [anonlogin] => -1 [PHPSESSID] => 94be8c1b429b6d71699ef1e6bb0ffcc7
> [imgnm] => Buffy.jpg )
>
> Output from print_r on, for example, /html/blogsection.php:
>
> Array ( [mad] => some other value [imgnm] => doubledecker.jpg
> [member_id] => 1 [pass_hash] => 3ea2565f212a118e5a808103fea59152
> [anonlogin] => -1 [PHPSESSID] => 94be8c1b429b6d71699ef1e6bb0ffcc7 )
Learn the basics about cookies. If you set a cookie in the html/ folder,
then it's only available for that folder and its subfolders (by
default).
If you want to set it in html/ and have it available on your entire
site, then set the 'path' value of the cookie in the setcookie()
function.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/