Cless Posted April 21, 2009 Share Posted April 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155121-iframes-and-php/ Share on other sites More sharing options...
premiso Posted April 21, 2009 Share Posted April 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155121-iframes-and-php/#findComment-815993 Share on other sites More sharing options...
Cless Posted April 21, 2009 Author Share Posted April 21, 2009 Ah, damn. Dx Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/155121-iframes-and-php/#findComment-815997 Share on other sites More sharing options...
soak Posted April 22, 2009 Share Posted April 22, 2009 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?? Quote Link to comment https://forums.phpfreaks.com/topic/155121-iframes-and-php/#findComment-816014 Share on other sites More sharing options...
mrMarcus Posted April 22, 2009 Share Posted April 22, 2009 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?? it would be possible, yes .. but as you said, no guarantee it'd be set by the time it was needed. Quote Link to comment https://forums.phpfreaks.com/topic/155121-iframes-and-php/#findComment-816023 Share on other sites More sharing options...
premiso Posted April 22, 2009 Share Posted April 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155121-iframes-and-php/#findComment-816039 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.