PDA

View Full Version : Iframe SSI II Outside domain question



Astonished Man
01-10-2007, 07:33 PM
1) Script Title: iframe ssi script II

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm

3) Describe problem: In the script instructions I know it says the pages all have to be in the same domain. But I was wondering if there might be room for one exception.

We have a service providing dynamic content for our site. These pages are created without wrapping and we include them in our site in an iframe. We have full access to the server that these pages are on so I was wondering if there was a way to include a script on each page to guage the size of the page and then pass the size variable to the parent page for resizing of the iframe.

Moving the pages to our server is not an option due to other issues. Any way to do this??

jscheuer1
01-10-2007, 09:52 PM
Unfortunately, the same security considerations that prevent the top page from querying the contained page for information, prevent it from receiving information actively sent from the contained page in these situations. There may be a workaround if your domain has PHP or another server-side language available to it but, that is beyond my expertise. If your domain does have PHP available, there are a few folks here at the forums who could probably help you if you posted about this in the PHP forum.

The basic idea is that with the intervention of PHP, a new page can be assembled on your domain with the content of the page from the other domain. Once this is accomplished, the script that you are using can operate without the restrictions mentioned on the demo page as long as it is this new page from the same domain that gets loaded into the iframe.

djr33
01-10-2007, 10:27 PM
In short, here's some PHP code that would help you--

<?php
ob_start(); //start output buffer*
include('http://address.com/page/and/stuff.php'); //include the page
//*if include is called normally, it just outputs it right away
//output buffer grabs that info instead
$page = ob_get_contents(); //now store to variable
$page = str_replace("'",'&#39;',$page); //replace ' with html entity
//if not, that will conflict in javascript later on
ob_end_clean(); //end output buffer
?>

Do your javascript stuff....
<script type="text/javascript">
....
var page = '<?php echo $page; ?>';
....
</script>


HOWEVER, note that it will be a problem if the included page contains stuff that conflicts with javascript, though I'm not sure what it is. I included a line changing ' to &#39;, so that should be good, but it may be a bit more complex.

However, this doesn't solve your problem, but it does get you ALL of the html, etc. from the page.

Astonished Man
01-10-2007, 10:33 PM
The page that contains the iframe is a php page so we are good on that. Not sure if I follow all that, but it sounds interesting. I'll check into it. Thanks.

djr33
01-10-2007, 10:44 PM
Each line is commented. It's really very simple.

The include statement gets the text (html) of the page it has in parentheses... any page. Then it outputs with the echo later on as a variable into a javascript variable.

jscheuer1
01-10-2007, 11:21 PM
I just tried this out on a domain that has PHP and had problems with the str_replace (it gave an error). As a result, the javascript didn't work but, it really doesn't need to for this. I changed the code to:


<?php
ob_start(); //start output buffer*
include('http://some.com/2006/directions.htm'); //include the page
//*if include is called normally, it just outputs it right away
//output buffer grabs that info instead
$page = ob_get_contents(); //now store to variable

ob_end_clean(); //end output buffer
?>

<?php echo $page; ?>

saved it as directions.php and got the directions page from the other domain. Style and images were not available but, the content was all there. But, this only worked retrieving a page from another domain that was on the same server and that was actually in a subdirectory of the retrieving domain's files. I couldn't get it to grab Google's home page or a page from another domain entirely that was a plain HTML file with just the word 'Hi' on it.

djr33
01-11-2007, 12:30 AM
Hmm. Not sure what's wrong with the str_replace.

http://www.php.net/manual/en/function.str-replace.php

OOOH

Grrr. Stupid interpreting of ascii characters.

$page = str_replace("'",''',$page);

it SHOULD be:
$page = str_replace("'",'&#39;',$page);

Sorry about that.

As for inputting to a variable, I was assuming you were going to try to analyze the html of the page, so figured that was the best way.

However, there's another way to do it.

1. use the PHP to get the html of the iframe in question and bring that to your server.
If you aren't trying to echo/alter the text of that site in a particular fashion, then just use include('http:///') and be done with it. You don't need to use any of the output buffer stuff, or the echo, etc. Just output directly.

2. get the height/width values.

3. to avoid having screwed up pages (missing linked content, like styles and images), use the REAL page, but with the height/width from the page in question.


Additionally, this is similar to a proxy, so you could actually parse the html and unlocalize the links so that they work.

That wouldn't be too hard.

Append to each href/src/etc the location of the page asked for, minus the filename itself. And you would need to account for ../ and / commands at the starts of links. But that is possible.


It all depends on what you plan to DO with the page.

The PHP I have supplied does it's job. Now it's up to javascript.