Skip to main content
Inspiring
October 10, 2015
Question

php session vars not showing up

  • October 10, 2015
  • 1 reply
  • 525 views

php session vars not showing up

I have a slightly odd setup (let's pretend we don't want to change this right now)

I have a HTML page on site 1

- on page1.html I have an iframe that goes to site2 (php)


<iframe src="http://mysite2.com/page2.php" ></iframe>


page2.php sets some session vars like

<?php

if(!session_id()) session_start();

$_SESSION["id"] = 123;

?>


- and then does a page jump to page3.php

echo '<meta http-equiv="refresh" content="2; url=ipage3.php">'

---- when I get to page3 the first time the session vars do not show up

like:

<?php

if(!session_id()) session_start();

echo $_SESSION["id"];

?>

---> but when I manually refresh the original site 1 page then it recycles everything and then successfully shows the session vars on page 3

Q: Curious why the session vars do not show up the 1st time around? Any idea how to fix this?

    This topic has been closed for replies.

    1 reply

    Rob Hecker2
    Legend
    October 10, 2015

    This is wrong:

    if(!session_id()) session_start();

    $_SESSION["id"] = 123;

    Right:

    session_start();

    if (is_numeric($_SESSION['id'])){

    echo "The session id is ".$_SESSION['id'];

    }

    But I don't know if that's your only problem. The sessions will be on mysite2. The first site won't have access to them.