简体   繁体   English

PHP会话变量未通过但会话ID相同

[英]PHP Session variables not passing but the session ids are the same

** SOLVED ** - Server Problem ** 已解决 ** - 服务器问题

As mentioned above, the session ids are the same on both pages but I can't access to the session variables.如上所述,两个页面上的会话 ID 相同,但我无法访问会话变量。 I need Session for a bigger project I created this to test it.我需要 Session 来创建一个更大的项目来测试它。 I don't have any Idea why since the ids are the same.我不知道为什么,因为 ID 是相同的。

First page:第一页:

<?php session_start();
echo "session started"
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
echo "<br>";
print_r(session_id());
echo "<br>";
echo "<a href='use.php'>Display</a>"
?>

</body>
</html>

Second Page:第二页:

<?php session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Echo session variables that were set on previous page
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
echo "<br>";
print_r(session_id());
?>

</body>
</html>

For those with the same problem: The problem was that the server( University project server which requires your uni login) required a login to access any file.对于那些有同样问题的人:问题是服务器(需要您的 uni 登录的大学项目服务器)需要登录才能访问任何文件。 That login started a session.该登录启动了一个会话。 When I wanted to start another session it just didn't worked.当我想开始另一个会话时,它没有用。 Solution you should use a server which is not requiring a login and than you can start your own session.解决方案您应该使用不需要登录的服务器,然后您可以开始自己的会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM