In my index.php file I have this

$answer = $a + $b;
echo '<iframe src="ianswer.php".....etc. etc.

ianswer.php contains only the following line

echo $answer;

But the ianswer.php doesn't know what $answer is.

If I change that line to

echo "RUBBISH";

The word RUBBISH appears in the iframe.

How do I get it to display the answer?

I searched the web and played around with GLOBAL, $GLOBALS and $_SESSION but none of the examples I found work.

Try:
echo '<iframe>';
include 'ianswer.php';
echo 'etc. </iframe>';

@cgull
That was smart and simple... I'll also try using it in the future. Any idea how to get info from an Iframe page into our PHP parent page?

Hi,
I never used iframe so I'm not sure, but I would say you would need to call the php parent page and send it parameters.

Something like:

<a href="parent.php?parameter1=something&ampparameter2=something">Call Parent</a>

I need more details of what you are trying to do, in order to help.

The idea of the IFRAME is to include web page inside other page with different configurations and functions, NOT TO WORK TOGETHER, only to display the iframepage content in the main page.
If your idea is to display the results from your main page you should not use Iframe.

How ever, if you want on some reason to be this way you may use a php GET function..

At your iframe code add src

<iframe src="page.php?answer=".$answer."">

And inside your page.php add

$answer=$_GET["answer"];

:)

Member Avatar for diafol

Do you really need to use iframe?
Why not just use an include?
I'm assuming that all these files are on the same domain.
The only 'advantage' I can see with this is the ease of changing content via js as it doesn't need ajax.

Hi

Thanks for all your help

sv3tli0 has come closet to solving my problem, but not quite.

If I change the code to $answer = '6';

The 6 gets passed to the file.

But when $answer = $a + $b nothing gets passed to the file.

When I view the source of the main page, with $answer = '6';

I get this <iframe src="page.php?answer=6"

But using $answer = $a + $b I get this

<iframe src="page.php?answer="

The value of $answer is not getting echoed in the html.

I tried adding echo $answer; on the line before the iframe code, and the value for answer appears there whether it is $a + $b or just '6'

$answer = $a + $b;

this is a math formula and it may only counts .
So if you have inputed $a and $b it will calculate to some number .
You can set

if(!$a&&!$b)$answer=0;

P.S. be carefull not to miss some element. You may copy paste your code here to make better advice.

Hi

Please ignore my previous post, sv3tli0's post was spot on.

I did not write the original code, but whoever did, created the address of the iframe page with a number of variables, i.e.

$PartOne = 'http://';
$PartTwo = 'www.';
$PartFive = '.com';

etc. etc.

For some reason he also had

$dq = chr(34);

And used $dq whenever he needed double quotes in the address.

I took out $dg and replaced it with real double quotes and it works perfectly now.

So a big thanks you to all those who helped.

For anyone interested, the reason he wanted it done this way is he gets paid $5 per month to have a banner on his site. But he can't have any other banners on the page unless they are in iframes.

He didn't want the obvious answer of having a separate html file to display each banner, then just load the relevant html file into the iframe. Instead he wanted to pass a variable to a php file and it would then know which banner to display.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.