• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

php session vars not showing up

Contributor ,
Oct 10, 2015 Oct 10, 2015

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?

Views

402

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 10, 2015 Oct 10, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines