I have one page (parent) which opens a second page via popup (child)
On the second page I have the following PHP code which gets the value of an HTML element from the parent page:
$var=print_r("<script type='text/javascript'>var x=window.opener.document.getElementsByName('name1');document.write(x[0].value)</script>",true);
When I echo the variable $var
I get exactly what I expect. Thus:
echo "test=" . $test;
... prints for example "Expenses" on the page.
So far so good.
The problem is when I try to write this variable to a file like:
$f=fopen("/mylog.txt","w+");
fwrite($f, $test);
fclose($f);
... then , instead of the actual value of $test
(e.g. Expenses),
I get the whole script tag in my logfile, thus:
<script type='text/javascript'>var x=window.opener.document.getElementsByName('name1');document.write(x[0].value)</script>
Assuming that print_r
with 'true' parameter returns the value to my $test
variable, why is it writing the exact script tag to the logfile?
How can I overcome this?