在test1.php上我有这个:
<?php
echo "Session variables are about to be set.";
// Set session variables
$_SESSION["animal"] = "cat";
echo "Session variables are set.";
echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>
<div ms_positioning="text2D" class="style7"><a href="javascript:winOpen();" test2.php="">Contact Information</a></div>
<script>
function winOpen() {
window.open("/test2.php",null,"scrollbars=no,resizable=no,width=600,height=300,top=100,left=100");
}
</script>
在test2.php中,我有这个:
<?php
// Echo session variables that were set on previous page
echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>
但是数据没有出现在test2.php上。它确实回应了test1.php。
有什么建议吗?
答案 0 :(得分:3)
您需要致电
session_start();
在脚本开头处起作用。
答案 1 :(得分:2)
加入fisrt代码
session_start();
试试这个
<?php
session_start();
// Echo session variables that were set on previous page
echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>
答案 2 :(得分:2)
你的test1.php应该是这样的:
<?php
session_start(); // In case you come back to test1.php
echo "Session variables are about to be set.";
// Set session variables
$_SESSION["animal"] = "cat";
echo "Session variables are set.";
echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>
<div ms_positioning="text2D" class="style7"><a href="javascript:winOpen();" test2.php="">Contact Information</a></div>
<script>
function winOpen() {
window.open("/test2.php",null,"scrollbars=no,resizable=no,width=600,height=300,top=100,left=100");
}
</script>
test2.php应该是这样的:
<?php
session_start();
// Echo session variables that were set on previous page
echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>