突然$ _SESSION [“用户名”];从登录屏幕发送, 在:
session_start();
$_SESSION["username"]=$username;
echo $username;
echo $_SESSION["username"]; // THESE 2 ECHOes WORK
在索引中:
<?php
session_start();
echo $_SESSION["username"];
// THIS ECHO IS BLANK ALREADY TRIED IT WIWH OTHER ECHOES THE PAGE WORKS
?>
答案 0 :(得分:0)
你的来电session_start();
太多次了。
尝试简单检查会话是否已启动
例如:
// start session if not session_id not present
if(session_id()=='') session_start();
您还可以检查是否有会话变量:
if(isset($_SESSION['username']) && $_SESSION['username'] !== "") // this checks if its set and does not equal nothing
{
//do your code
}
else
{
//reset $_SESSION['username'];
}