cjkeane Posted April 9, 2011 Share Posted April 9, 2011 hi everyone. i'm wondering what the best way is to create a session variable and pass it to an iframe. i need to do something along these lines, but it doesn't seem to pass the ID. Any hints on how i should accomplish this? session_start(); $_SESSION['ID']=$_GET['ID']; // id from previous page $ID=session_id(); <iframe src="iframepage.php?ID=<?php echo $ID; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/ Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 Does your code look like this? <?php session_start(); $_SESSION['ID']=$_GET['ID']; // id from previous page $ID=session_id(); ?> <iframe src="iframepage.php?ID=<?php echo $ID; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> Or is the code you posted the actual code? If so, you need to start and end the PHP tags. And put the iframe tag outside the PHP tags. Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199116 Share on other sites More sharing options...
cjkeane Posted April 9, 2011 Author Share Posted April 9, 2011 sorry. i forgot to add the php tags. but yes thats what i had inside php tags. the id just isn't displayed so i'm wondering if the session code is correct. Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199124 Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 Try this code: <?php session_start(); $_SESSION['ID'] = $_GET['ID']; //echo id to see if it is what you expect echo $_SESSION['ID']; ?> <iframe src="iframepage.php?ID=<?php echo $_SESSION['ID']; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199129 Share on other sites More sharing options...
cjkeane Posted April 9, 2011 Author Share Posted April 9, 2011 ok. the id is echoed to the screen, but not passed to the iframe. Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199131 Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 Well, I tested it an it worked on my localhost. Are you sure it's not passing it through? Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199134 Share on other sites More sharing options...
cjkeane Posted April 9, 2011 Author Share Posted April 9, 2011 i'm pretty new to sessions. how do i grab the session in the iframe? i mean, do i need to start the session as well? Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199135 Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 i'm pretty new to sessions. how do i grab the session in the iframe? i mean, do i need to start the session as well? Did you use the code I gave you? <?php session_start(); $_SESSION['ID'] = $_GET['ID']; //echo id to see if it is what you expect echo $_SESSION['ID']; ?> <iframe src="iframepage.php?ID=<?php echo $_SESSION['ID']; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> session_start(); already starts the session. While I'm here, may I ask why you are using session? $_GET['id'] already contains the value you want, why not just make it: <iframe src="iframe.php?ID=<?php echo $_GET['id'] ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="5" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199137 Share on other sites More sharing options...
cjkeane Posted April 9, 2011 Author Share Posted April 9, 2011 I was attempting to use session variables because hopefully that way i wouldn't lose the ID number passed from the main page to the iframe. you see, in the iframe, there is a submit form with a list of files that can be deleted, and when the file is deleted, the link between the main page and the iframe is broken. i need a way to maintain the link between the main page and the iframe after the data is updated in the iframe. i hope that makes sense. ADDED NOT: The way it functions now, the page needs to be refreshed manually so that the iframe data is refreshed. i'd like not to have to keep refreshing the page manually. Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199138 Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 I was attempting to use session variables because hopefully that way i wouldn't lose the ID number passed from the main page to the iframe. you see, in the iframe, there is a submit form with a list of files that can be deleted, and when the file is deleted, the link between the main page and the iframe is broken. i need a way to maintain the link between the main page and the iframe after the data is updated in the iframe. i hope that makes sense. ADDED NOT: The way it functions now, the page needs to be refreshed manually so that the iframe data is refreshed. i'd like not to have to keep refreshing the page manually. You could use something like this: header("location:url"); Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199143 Share on other sites More sharing options...
cjkeane Posted April 9, 2011 Author Share Posted April 9, 2011 already tried that, plus many different variations of javascript refreshes of the parent window. i just tried <?php session_start(); $_SESSION['ID'] = $_GET['ID']; $ID = session_id(); ?> in the main page and in the iframe <?php $ID = $_REQUEST['ID'] ; if(session_id() == "") { session_id($ID); session_start(); echo "<br> sessId: " . $ID . "<br>" ; } ?> The id is displayed in the iframe, but as soon as the iframe is updated through a submit button, then i lose the session ID. the only way to get the ID back is for the whole page to be refreshed, but then when files are deleted from inside the iframe, the data sometimes doesnt delete. which is why i wanted to try using sessions. Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199148 Share on other sites More sharing options...
3raser Posted April 9, 2011 Share Posted April 9, 2011 already tried that, plus many different variations of javascript refreshes of the parent window. i just tried <?php session_start(); $_SESSION['ID'] = $_GET['ID']; $ID = session_id(); ?> in the main page and in the iframe <?php $ID = $_REQUEST['ID'] ; if(session_id() == "") { session_id($ID); session_start(); echo "<br> sessId: " . $ID . "<br>" ; } ?> The id is displayed in the iframe, but as soon as the iframe is updated through a submit button, then i lose the session ID. the only way to get the ID back is for the whole page to be refreshed, but then when files are deleted from inside the iframe, the data sometimes doesnt delete. which is why i wanted to try using sessions. If you have a form, you could always check for a second value using a hidden form. <input type='text' name='id' value='". $ID ."'> Quote Link to comment https://forums.phpfreaks.com/topic/233165-create-session-and-pass-session-to-iframe/#findComment-1199149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.