Jump to content

IFrames and PHP


Cless

Recommended Posts

I need to create an iFrame, however, I need to make the PHP executed before it be global. For example:

 

<?php

$hi="blah";

?>

<iframe src='frame.php' width='100' height='350'>

 

Then, in "frame.php", the iFrame I am calling, I would want to be able to use the variable I defined before it ($hi). Not really a very practical example, but yeah.

 

Thanks.

Link to comment
Share on other sites

You cannot do that with PHP. The variable would have to be passed to the frame.php via Javascript or GET.

 

This would allow you to use $_GET['hi'] to get that variable:

 

<?php

$hi = url_encode("blah");
$another = url_encode("hello bob");

?>

<iframe src='frame.php?hi=<?php echo $hi; ?>&another=<?php echo $another; ?>' width='100' height='350'>

 

url_encode ensures that the string is passed correctly. Then in the frame.php script:

 

<?php
$hi = isset($_GET['hi'])?$_GET['hi']:null;
$another = isset($_GET['another'])?$_GET['another']:null;

if (!is_null($hi)) 
    echo "You passed in {$hi} for the hi.";

if (!is_null($another))
    echo "You passed in {$another} for the another.";
?>

 

A very simple example, but should get the point across.

Link to comment
Share on other sites

Would it be possible to use the $_SESSION var or would it not be guaranteed to be set by the time the iframe was called??

 

I think it would be set. As long as they had session_start() at the top of each page. There is no reason for it not to as PHP is done on the server not the client. The guarantee would actually be 100% certain due to that fact.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.