会话变量不会转移到其他页面 [英] Session Variables Not Carrying Over to Other Pages
问题描述
我的第一页是:
其他页面是:
第二页没有输出.错误日志输出:
[2013 年 10 月 30 日 12:13:53] PHP 警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送
是否有任何关于问题可能是什么的想法?会话变量可以在第一页上正常输出(当我测试时),但不能在第二页上输出.谢谢.
如果您在应用程序中使用会话,那么您必须在页面的最顶部启动会话,并且必须避免在
之后出现空格或额外的行空格>
和
session_start();
按如下方式编写代码:
在第二页,
希望这能解决问题,如果仍然没有,那么您可以使用以下技术:
在第二页,
My first page is:
<?php
session_start();
$_SESSION['test'] = 'testSession';
?>
Other page is:
<?php
session_start();
echo $_SESSION['test'];
?>
There is no output on the second page. The error log outputs:
[30-Oct-2013 12:13:53] PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
Are there any ideas as to what the problem might be? The session variables can be outputted fine on the first page (when I tested), but not on the second. Thank you.
If you are using sessions in your application then you must start the session at the very top of your page, you must avoid spaces or extra line spaces after
<?php
and
session_start();
Write your code as follows:
<?php
session_start();
$_SESSION['test'] = 'testSession';
?>
and on second page,
<?php
session_start();
echo $_SESSION['test'];
?>
Hope this solves the problem, and if still not then you may use following technique:
<?php
ob_start();
session_start();
$_SESSION['test'] = 'testSession';
?>
and on second page,
<?php
ob_start();
session_start();
echo $_SESSION['test'];
?>
这篇关于会话变量不会转移到其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!