PDA

View Full Version : Iframe SSI script II - External URL



egr103
07-31-2008, 01:32 PM
1) Script Title: Iframe SSI script II

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

3) Describe problem:

I have recently added this invaluable script to my web site. I have however reached a point where i wish to incorporate an external web page.

I am fully aware that the script does not support external web sites. However i have thought about URL masking or page re-direction.

The 2 URL's in question are:

Internal/hosted page (containing the iframe code) domain:
http://idl.newport.ac.uk

External domain: http://mycommunity.newport.ac.uk/cs/blogs/idlnews/Default.aspx

1) The code currently on the host page looks like this (the url is linking to the external domain from the host page and will not work):


<iframe id="IDLBlog" src="http://mycommunity.newport.ac.uk/cs/blogs/idlnews/Default.aspx" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:visible; width:100%; display:none"></iframe>

2) I do have the power to mask this external URL to look like the same domain as the hosting page. So the code will now look like this:


<iframe id="IDLBlog" src="http://idl.newport.ac.uk/idlnews" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="overflow:visible; width:100%; display:none"></iframe>

Will masking the external url (1) disguise/hide (in the hosted page) the fact that it is hosted elsewhere? Will it work?

Thanks in advance guys!

ddadmin
08-01-2008, 04:40 AM
it really depends on how you're masking the external URL to appear as if it's local. About the only way I can think of is if you actually first fetch the contents of the external page using PHP (ie: via file_get_contents (http://ca.php.net/manual/en/function.file-get-contents.php)) or Curl, then including that local page using the script. That would be similar to creating an Ajax proxy to make a request on any external URL. Any type of "virtual" masking most likely will fail based on cross browser JavaScript security restrictions in modern browsers.

egr103
08-01-2008, 08:33 AM
I will be masking it by making a dsn entry that will forward to the external domain.

Will that work at all?

Also, i'm afraid to say i'm quite useless when it comes to PHP as i have no experience of using it.

From that then i'm guessing it is a lost cause?

ddadmin
08-01-2008, 11:58 AM
DNS redirect (A record) may work, though I'm not entirely sure. The browser may also check other credentials of the two servers to make sure they match (IP address for example).

PHP's "file_get_contents" simply grabs the contents of any URL and outputs it as a string. The idea is to use that function to fetch and create a local copy of the external page on your server, then the Iframe SSI script would display that local copy of the file instead. You may create a blank php file (ie: external.php) containing:


<?php
echo file_get_contents("http://othersite.com/test.htm");
?>

Then have the Iframe SSI script show external.php. You should be able to get all the details on this function at php.net (http://ca.php.net/manual/en/function.file-get-contents.php)

egr103
08-01-2008, 12:26 PM
This is excellent. It does the job and automatically adjusts to show all content, however...

The external page i am calling in loses it's css styling elements.

see this url:
http://idl.newport.ac.uk/misc/idl-news-iframe.html

But the page being called in looks like this:
http://mycommunity.newport.ac.uk/cs/blogs/idlnews/

SO the page content appears, but with no styling.

Is there a way around this at all? For example, by echoing the CSS style sheet as well as the web page?

I have also noticed that i cannot link to other pages that are on that external domain.

I will need to link to various other pages in the domain...but this doesn't work with this method. Is there a way of viewing other pages in the external domain by modifying the php?

ddadmin
08-01-2008, 07:24 PM
Well, external CSS and JS files referenced on the external page can just be included within the output as is, without echoing their actual source code. So you may have something like:


<?php
echo '<link rel="stylesheet" type="text/css" href="http://www.othersite.com/style.css" />';
echo file_get_contents("http://othersite.com/test.htm");
?>

egr103
08-04-2008, 08:17 AM
Brilliant, thanks for your help on this.

In my previous post i mentioned a problem with linking to different pages within the iframe. Obviously the current main page i am echo-ing (referenced in the PHP) will appear, but that page will have links to other pages within that external domain.

Please see this link and then click any of the links in the white space (no styles applied to the text) - times new roman font. They are all blog posts.

http://idl.newport.ac.uk/misc/idl-news-iframe.html

You will notice that a server error occurs when you click on the links, how do i get these links to link to the proper pages and not return a error? Note: I do not have control over the other html pages so therefore cannot alter the source code of the html (i.e. the a href tags).

If this cannot work then can you suggest any other methods that can get around this problem?

Thanks again, ddadmin