会话变量不显示 [英] Session variable not displaying
问题描述
所以我在一个页面上创建一个会话并创建一个名为 uName 的新变量并分配一个值.我转到另一个页面并尝试回显该值,但出现错误:未定义变量 _SESSION"
So I create a session on one page and create a new variable called uName and assign a value. I go to another page and try to echo the value but I get an error:"Undefined variable _SESSION"
代码如下:
我开始会话并创建变量 uName 的页面
The page where I start the session and create the variable uName
<?php
session_start();
$_SESSION['uName'] = "Mike";
?>
我尝试回显变量值的页面:
The page where I try to echo the variable's value:
<?php echo "My Name is " . $_SESSION['uName'];?>
我的代码中除了页面的外壳之外没有其他任何东西,只有 html、标题、标题、正文和段落标签,全部正确嵌套.
There is nothing else in my code except for a shell of a page just html, head, title, body and paragraph tags, all properly nested.
推荐答案
您需要在新文件的开头再次调用 session_start(),如下所示:
You need to call session_start() again at beginning of the new file, like so:
<?php
session_start();
echo "My Name is " . $_SESSION['uName'];
这篇关于会话变量不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!