我注意到当我离开时我的 php session ID 发生了变化
https://www.mathtutortime.com/tutor/tutor至 https://www.mathtutortime.com/account/get_tutoring/lobby.html .
如果我从这里出发,效果很好
https://www.mathtutortime.com/account/至 https://www.mathtutortime.com/account/get_tutoring/lobby.html 。
我认为 session ID 不会保留在不同的域中。
我的代码为https://www.mathtutortime.com/tutor/tutor有我已经存储在
中的 session 信息https://www.mathtutortime.com/tutor 。 https://www.mathtutortime.com/tutor/tutor中的代码是:
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
window.location.replace("https://www.mathtutortime.com/account/get_tutoring/lobby.html")
</script>
</head>
<body>
</body>
</html>
在obby.html,我有:
<?php session_start();
echo session_id();
if($_SESSION['loggedin'])
{
echo "yelo";
if(!$_SESSION['tutor'] && $_SESSION['minutes'] > 0)
{
...
?>
现在,如果我在重定向后重新加载obby.html, session ID 似乎会重置回原来的状态。这意味着它在重新加载页面后起作用。我认为这是因为我能够克服
if($_SESSION['loggedin'])
lobby.html 中的部分,当我回显它时,我可以看到 session ID 发生变化。
因此,我认为 session 信息确实会持续存在,但只有当我使用 window.location.replace 等重定向时才会失效。但我不知道为什么。
感谢您的帮助。
最佳答案
改变这个
<?php session_start();
?>
<!DOCTYPE html>
<html>
要成为这样,这样在 session_start() 之前就不会渲染空格(或任何其他字符)。
<?php session_start();
?><!DOCTYPE html>
<html>
你的 !doctype 前面也不应该有空格,但这不是问题。
关于javascript - 为什么 session ID 不保留在同一域中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60030537/