我有一个会话:
session_start();
$_SESSION['auth'] = "true";
并设置PHPSESSID Cookie 。但是,当我刷新页面时$_SESSION['auth']
返回NULL。此外,当我致电session_destroy();
时,收到错误Trying to destroy uninitialized session
如何保持会话开放? 谢谢!
答案 0 :(得分:2)
尝试一下..如果有效,我会检查你的代码+注释session_destroy ...
page1.php中
<?php
session_start();
$_SESSION['auth'] = "true";
$_SESSION['superhero'] = "batman";
?>
<a href="page2.php">Click here</a>
使page2.php
<?php
session_start(); // start the session before using it
echo $_SESSION['auth']; // will output 'true'
//print_r($_SESSION); // uncomment for testing
?>