Jump to content

Create session and pass session to iframe


cjkeane

Recommended Posts

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>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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 ."'>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.