Forum Moderators: coopster
I have a page. The page is dynamic with pretty much infinate variables. On the page there is an iframe that contains a php page.
The php page is there to deliver content based on the page title of the main page (the page with the iframe)
The php script reads the main page title then tries to include a file with the page title as a query string.
Here is some simple code I used...
<?php
$url = $HTTP_REFERER;
$file = fopen ("$url", "r");
if (!$file) {
echo "<p>Can't grab title.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
if (eregi ("<title>(.*)</title>", $line, $out)) {
$title = $out[1];
break;
}
}
fclose($file);
$q = urlencode ($title);
include "http://www.example.com/folder/file.php?keywords=$q";
?>
When I view main page i get the following error within the iframe...
Warning: Failed opening 'http://www.example/com/folder/file.php?keywords=foo' for inclusion (include_path='.:/usr/share/php') in /home/site/public_html/ad.php on line 17
In this example it passed "foo" as the keyword because it was the main page title for the page with the iframe.
At first I though php includes where not posible due to my php.ini configuration but I checked and this feature was set.
Any ideas.. Thanks in advance.
Mack.
Type the same address into a web browser, look at it, that's what's being included.
This means that the file on the other server shouldn't look like:
<?php
$this = 'that';
somefunc('someparam');
?>
It needs to be:
<?php
echo "
<?php
$this = 'that';
somefunc('someparam');
?>
";
or just put it in a static .txt file and include that.
Or do you want to capture the output and process it?
As Minck said, though, you can't pass a GET parameter to an include, since it's not an HTTP request.
So [example.com...]
is really more like
$param = val
include (http://www.example.com/page.php);
Since you may have permission issues and so on, you may want to do something like
clearstatcache();
$file = 'http://www.example.com/page.php';
if (is_file($file) && is_readable($file))
{
include($file);
}