|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-10-20 19:59 UTC] joe at kybert dot com
Description:
------------
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
<servername>/test/<filenames>
.
File 2 fails to read the cookie!
Reproduce code:
---------------
file1.php contains:
<?php
setcookie("test", "set_by_file_1", time()+3600, "/", $_SERVER['HTTP_HOST']);
echo "file 1 cookies: ";
print_r($_COOKIE);
include("http://$SERVER_NAME/test/file2.php");
?>
file2.php contains:
<?php
echo "<br>file 2 cookies: ";
print_r($_COOKIE);
?>
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 ( )
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
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: include("{$_SERVER['DOCUMENT_ROOT']}/test/file2.php?myparam=hello"); joe #