user523234 February 2016

Session data could not be read from another window

On a test1.php I have this:

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

In test2.php, I have this:

<?php
    // Echo session variables that were set on previous page
    echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>

But data is not showing up on test2.php. It did echo back on test1.php.

any suggestions?

Answers


paranoid February 2016

Put in fisrt of code session_start();

Try this

<?php 
session_start();
// Echo session variables that were set on previous page
echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>


jcubic February 2016

You need to call

session_start();

function at the beginning of the script.


Atif Tariq February 2016

Your test1.php should be like this:

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

And test2.php should like this:

<?php
    session_start();
    // Echo session variables that were set on previous page
    echo "Favorite animal is " . $_SESSION["animal"] . ".";
?>

Post Status

Asked in February 2016
Viewed 2,229 times
Voted 6
Answered 3 times

Search




Leave an answer