我有一个会话:
session_start();
$_SESSION['auth'] = "true";
并设置了 PHPSESSID cookie 。但是,当我刷新页面$_SESSION['auth']
时返回 NULL。此外,当我打电话时,session_destroy();
我收到错误Trying to destroy uninitialized session
如何保持会话打开?谢谢!
试一试..如果可行,我将重新检查您的代码+注释掉 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
?>