Hi,
I have a very basic idea of PHP session management. From what I know, in order to maintain variables across multiple scripts in an app. we can store them in a session.
I have a main page - index.php in which I have an iframe referencing another php script - bar.php. All I am trying to do is access the session variables from the index page in the iframe, which, so far I haven't been able to accomplish.
My code is as follows:
index.php
bar.php
Earlier I noticed that simply saying session_start() in the iframe-script was actually creating a new session with a different session id, hence I appended the session id from index.php into the iframe URL so that I can try to access the same ongoing session from bar.php, but print_r($_SESSI ON) doesnot show me anything.
Where might I be going wrong? Any suggestions?
I have a very basic idea of PHP session management. From what I know, in order to maintain variables across multiple scripts in an app. we can store them in a session.
I have a main page - index.php in which I have an iframe referencing another php script - bar.php. All I am trying to do is access the session variables from the index page in the iframe, which, so far I haven't been able to accomplish.
My code is as follows:
index.php
Code:
<?php session_start(); $_SESSION['myVar']="hello" ; $sessId=session_id(); echo "<br> sessId: " . $sessId . "<br>" ; print('<iframe name="test" id="test" src="foo/bar.php?sessId='.$sessId.'" marginwidth=0 marginheight=0 onload="this.height=this.contentDocument.height" width="100%" frameborder="0" scrolling="yes"></iframe>'); ?>
bar.php
Code:
<?php $sessId = $_REQUEST['sessId'] ; if(session_id() == "") { session_id($sessId); session_start(); echo "<br> sessId: " . $sessId . "<br>" ;//shows the same session-id as index.php echo "<pre>" ; print_r($_SESSION); //shows an empty array } else { //something } ?>
Where might I be going wrong? Any suggestions?
Comment