简体   繁体   中英

Cannot store data to session

I cant carry my session throughout files.

I checked

  • I have session_start() at the beginning of each file

  • Used notepad, so no unseen BOM characters added by IDE

  • No error, warning etc.

  • Sessions are enabled (see phpinfo() output below )

  • No rewrites etc.

So my files are as follows

a.php:

session_start();
$_SESSION["test"] = "value";
header("Location: b.php");
exit;

b.php

session_start();
echo "session: ";
print_r($_SESSION);

output of b.php :

session: Array ()

phpinfo() output:

在此处输入图片说明

(Also session_id() is same in both files, and I have a session cookie file.)

Only thing I can think of is session save path may not have write permission, but this is a shared host, so I assume this is not the case (I'll check with the host porvider anyway)

What am I missing here?

on page b.php

use this code

session_start();
echo $_SESSION["test"];

instead of

session_start();
echo "session: ";
print_r($_SESSION);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM