Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.