2016-11-23 98 views
0

嗨我有一個基本的會話代碼,用於測試我已經上傳到兩個不同的服務器。PHP會話不能在不同的服務器上工作

文件1 -

<?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> 

文件2 -

<?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信息服務器1: http://thycart.in/adaptyapp/phpinfo.php

PHP信息服務器2: http://103.231.209.162:60070/phpinfo.php

出於某種原因,會議沒有在一個server.Please幫助一起查找原因。謝謝

+1

請參考這可能會解決您的查詢.http://stackoverflow.com/questions/155920/php-session-data-not-being-saved – Akshay

回答

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> 
相關問題