PHP会话不在不同的服务器上工作

时间:2016-11-23 11:47:52

标签: php session server phpinfo

您好我有一个用于测试的基本会话代码,我已将其上传到两个不同的服务器。

File1 -

<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>

<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>

</body>
</html>

File2 -

<?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"] . ".";
?>

</body>
</html>

我们可以访问我们在第一页上设置的会话信息。

服务器1的链接:

http://thycart.in/adaptyapp/1.php

http://thycart.in/adaptyapp/2.php

服务器2的链接:(不工作)

http://103.231.209.162:60070/1.php

http://103.231.209.162:60070/2.php

PHP Info Server 1: http://thycart.in/adaptyapp/phpinfo.php

PHP Info Server 2: http://103.231.209.162:60070/phpinfo.php

由于某种原因,会话无法在一台服务器上运行。请帮助找到原因。谢谢

1 个答案:

答案 0 :(得分:0)

<?php
session_start();

?>
<!DOCTYPE html>
<html>
<body>

<?php
// Echo session variables that were set on previous page
 if(isset($_SESSION)) {


 echo "Favorite color is " .$_SESSION["favcolor"] . ".<br>";
 echo "Favorite animal is " .$_SESSION["favanimal"]. ".";
  }

 ?>

 </body>
 </html>