|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25929 cannot read cookies within included file
Submitted: 2003-10-20 19:59 UTC Modified: 2003-10-22 01:55 UTC
From: joe at kybert dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.2 OS: XP (debug server)
Private report: No CVE-ID: None
 [2003-10-20 19:59 UTC] joe at kybert dot com
Cookie is not readable across multiple files.

I have 2 files, file 1 sets a cookie (refresh file after 1st exe so cookie is sent)

it then includes file 2, which reads and displays the cookie.

Both files are in the same folder on the server, which is

File 2 fails to read the cookie!

Reproduce code:
file1.php contains:

setcookie("test", "set_by_file_1", time()+3600, "/", $_SERVER['HTTP_HOST']);
echo "file 1 cookies: ";

file2.php contains:

echo "<br>file 2 cookies: ";

Expected result:
file 1 cookies: Array ( [LastUser] => ujoe [test] => set_by_file_1 ) 
file 2 cookies: Array ( [LastUser] => ujoe [test] => set_by_file_1 )

Actual result:
file 1 cookies: Array ( [LastUser] => ujoe [test] => set_by_file_1 ) 
file 2 cookies: Array ( ) 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-21 15:17 UTC]
If you include REMOTE file, of course the cookie is not passed to it.

 [2003-10-21 16:05 UTC] joe at kybert dot com
Why not? The remote file is on the same server, and the cookie was set to be accessable to all files from that domain.

If you dont include it this way, you cannot pass arguments to the included file, this doesnt work:


 [2003-10-21 16:38 UTC]
I assumed from your first post that when you were 
including the file through http, you weren't parsing on 
the remote server. (I've seen similar set ups before. Not 
recommended, though, or necessary in virtually all cases.) 
You can't see the cookie in $_COOKIE from the second file 
because it's not being requested from the machine you see 
the cookie on, but rather the script that does the 
include. If you requested the file as source rather than 
parsed so that it would be parsed via the first file, it 
would probably work. 
Your second example of passing arguments to the second 
file won't work either because you can't pass arguments to 
a script that way. Just make some variables before 
including the file, the second file will see them. 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 01:01:28 2024 UTC