[英]session_start() not working in xampp
I created two files 1.php 2.php which are in the same folder(i am using xampp). 我在同一个文件夹中创建了两个文件1.php 2.php(我正在使用xampp)。 In 1.php used session_start() and also used $_session['name']=abc. 在1.php中,使用了session_start()和$ _session ['name'] = abc。 Then i opened 2.php to check whether session was created or not 然后我打开2.php检查会话是否已创建
2.php: 2.PHP:
<?php
if(isset($_session['name'])){
echo $_session['name'];
}
else{
echo "no session found!!";
}
?>
and it keeps on saying "no session found!!" 并不断说“找不到会话!”
Plz help ... 请帮助...
I searched a few sites n they say that by default d session is for whole folder containing d script and session_set_cookie_params($lifetime,'/') (where $lifetime=60*60) is also nt helping. 我搜索了几个站点,他们说d会话默认是包含d脚本的整个文件夹,session_set_cookie_params($ lifetime,'/')($ lifetime = 60 * 60)也有帮助。 On d other hand if at d end of1.php i use require("2.php") then abc is displayed. 另一方面,如果在1.php的末尾我使用require(“ 2.php”),则显示abc。
What you have done is right in 1.php
, however, 2.php
must start the session before using it. 您所做的一切在1.php
是正确的,但是2.php
必须在使用之前启动会话。
2.php 2.PHP
<?php
session_start();
if(isset($_SESSION['name'])) {
echo $_SESSION['name'];
}
else{
echo "no session found!!";
}
?>
You need to call session_start();
您需要调用session_start();
again at the top of every page where you want to access $_SESSION
variables, not only on the page where you want to initiate the session. 再次在您要访问$_SESSION
变量的每个页面的顶部,不仅在您要启动会话的页面上。
<?php
session_start();
if(isset($_SESSION['name'])){
echo $_SESSION['name'];
}else{
echo "no session found!!";
}
?>
You're missing session_start()
at the top of your 2.php
file which is needed to access $_SESSION
variables. 您缺少访问$_SESSION
变量所需的2.php
文件顶部的session_start()
。
<?php
session_start(); // missing
if(isset($_SESSION['name']))
{
echo $_SESSION['name'];
}
else
{
echo "no session found!!";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.