Link to home
Start Free TrialLog in
Avatar of MrsCRJ
MrsCRJ

asked on

How do I embed an external URL (on the same domain) without an Iframe?

Hello. I've searched but couldn't find the answer. In brief, I am using Joomla. I have installed a standalone PHP script as a subfolder under Joomla. I want to embed (or perhaps access is the better word) the external application within Joomla's main page. I have written a bridge component so that the two applications communicate to each other. I simply want the end user to be able to access this second application without being taken out of Joomla's page. I have an iframe within my bridge  component that works beautifully (auto resizes, etc). But, I'd like a better approach if there is one.

So... is there some combination of PHP/Ajax/Javascript (etc.) that can work here? Again, I just want a simple visual integration of this application into Joomla. Iframe achieves this, but I want a solution that behaves better cross-browser (and because some of my beta testers expressed dislike of iframe). Thanks.
Avatar of glcummins
glcummins
Flag of United States of America image

You can use cUrl to request the page on the server-side, and display the contents to the user in any format you like. For more information, see:

http://www.php.net/curl
http://curl.haxx.se/libcurl/php/
http://curl.haxx.se/libcurl/php/examples/getpageinvar.html
http://www.phpit.net/article/using-curl-php/
If you're Joomla page is able to interpret php, then the solution could be as simple as

<?php
echo file_get_contents([your iframe url]);
?>

However, this would likely fail as soon as your user tries to interact with the application.

If, in the likely event that it's not as simple as the first suggestion, then an AJAX approach might work, though it could be pretty complicated. You would want to grab the application interface through php, change any user-interaction to take place through javascript processes (preg_replace_all could possibly accomplish this), and then send it to the browser, probably using javascript. To send back any data, use AJAX get or post methods as appropriate, retrieve the response (again changing user interaction to use javascript processes) and display it back to the browser. From where I sit this would be a complicated task, but not an impossible one.

It just leaves one question: How important is it to get rid of this iframe?
Avatar of ll_jaxn
ll_jaxn

I know nothing about JAMIA, but is sounds like you want to execute the PHP program and display the output from within JAMIA.

If you can execute a system command in JAMIA, try executing "PHP path/yourphp.php" and pipe or tunnel the output to JAMIA to send to the Browser.  There is a command line option,I think
PHP -NOHEADERS scriptname,  This will keep PHP from sending the DOCTYP and header info to STDOUT
When you want to include another site you can use stuff such as cURL but if your wanting the user to be clicking on the included site then enclosing the site in the iframe or frame is the only way to keep the user on your site. If you use cURL or something to include the other site and the user clicks the links then they will be taken away from your site and taken to the URL for each link. The frame/iframe lets the user use both sites without being taken away from your page. So in short running a second site or application on your page will require that frame/iframe. You can also use <div> containers and ajax if you would like to get rid of the iframe as seen in this example:

http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Hope that helps :)
Avatar of MrsCRJ

ASKER

Thanks for the replies thus far. To answer earlier comments/questions, the application that I'm trying to embed via URL will absolutely be used by my site members. I'd prefer that they could navigate the "embedded" application and use it normally without being taken out of Joomla (the "parent" app if you want to call it that).

I defer to the experts as to whether iframes are a valid solution. I am superficially familiar with AJAX, but not nearly comfortable enough with it to know whether it'll provide the solution I'm looking for.

I can tell you, my beta testers (who themselves are webmasters and would be using the bridged application on their sites) are very concerned with usability and Google indexing. Those, along with cross-browser issues, were the biggest issues they stated with using an iframed approach. Are these concerns unfounded? Would an AJAX-based solution be preferable?
I don't know what percentage of visitors to a site would have issues with using iframes, but I'd think it would be pretty small. As far as Google indexing, I'm pretty sure that's a legitimate concern. I'm not positive, but I don't think the google bot is sophisticated enough to relate information embedded in an iframe with the page it's indexing.

That said, while I believe AJAX is possible is could be very difficult. Are you merely accessing this service, or do you actually control the service itself? If you control the actual service, then AJAX may not be terribly difficult after all.
Avatar of MrsCRJ

ASKER

@ MasonWolf:

Sorry for my ignorance (newbie here). Regarding "control the service," both Joomla and the package I want to embed are hosted on my server, installed by me (no remote sites or URLs involved). Not sure if this is what you meant, though.
That's what I meant yes. It might have been that you were accessing an external service such as a Google map over which you had little real control.

In your case, you can use AJAX methods with PHP proxies. Basically, you have to provide the other webmasters with both the javascript code for displaying, and the php code for fetching, the content of your service. Set up your service to provide well-formatted XML responses according to the inputs provided by the external sites' visitors. The responses can be parsed on the other sites' ends and used to generate HTML for display on their Joomla pages.

This is probably going to be more work than you can get just by having someone at EE pick at your code, but you should be able to hire someone who could do it if it's beyond your own skill.

One problem though, is that these other webmasters are concerned about Google being able to index the content as part of their own websites. Using javascript this way means they still won't get this content indexed as it changes. However, if the Joomla page can interpret php, or if your service can be fed into a Joomla content database and served through the normal Joomla page display, then the search engines will have no problem spidering it.

I'll be perfectly honest though, we're talking in such vague and abstract terms that I can't even say for sure which path can work for you. What does this service do anyway?
Avatar of MrsCRJ

ASKER

Sorry... I think my situation is simpler than I'm describing.

I am using Joomla as my main application (CMS). I am using a program called eFiction (located at efiction.org) so authors/writers can house and share their stories online. Joomla's native articles system was simply not designed to handle the nesting level that, say, novels may require.

That said, eFiction is really a simple PHP application. The real problem I had trying to use other embed methods (i.e., ob_start, include, etc.) is that, at its core, the developers are using a PHP templating engine called "TemplatePower". Rather than try to fight this thing, what I'm really trying to accomplish is:

" Have eFiction render normally (i.e,. as if it were directly accessed by a browser)

" Return the fully formatted output of eFiction to Joomla embedded in a way that members can navigate and use the software.

" Avoid any nasty hacking

I've looked into a lot of potential solutions (even reading up on JSON, JQuery, AJAX, and some obscure PHP functions), but all of this is well beyond my coding abilities at this time.

Given this scenario, is there a method for sanely embedding same-server php scripts similar to the relative simplicity of iframe? Or, is the complexity just not worth it. Again, I have Joomla and eFiction talking to each other via component-bridge, so there is now unified login, sharing of data between user tables, etc.
Are the novels hosted from your site?
Avatar of MrsCRJ

ASKER

Well, as a matter of fact... yes. eFiction allows for chapters and subchapters. Think of it as a CMS for writers. So, the person could literally store "War and Peace" or "The Fellowship of the Rings" using this software. eFiction was specifically designed as an archival system for writers. You can either upload text documents into the system, or type stories in natively through its WYSIWYG editor. It is an open source product. To my knowledge, there is no other software that does what this does that is as relatively easy to interface with.

That is why, whatever solution I choose, the ability of the user to use the software as it was intended must remain intact.

If there is no method other than iframe to embed this software, I may either have to let it run unembedded, or figure out a way to trigger this software successfully within the bridge-component. Again, the forced use of a templating engine (TemplatePower) further complicates that possibility.
That makes things very complicated, since you're trying to have a CMS serve up content not actually in its database. You can use AJAX to retrieve each page, but none of it would ever be indexed by the search engines. This is because Google doesn't actually interpret javascript.

If Joomla were taken out of the equation, the solution would be to just use php to request each page from your server, and use what (to the search engines) look like normal links for navigation. As is, see if you can specify a Joomla page with the following code:
<?php include('pagereader.php'); ?>

pagereader.php, if called, would have access to any $_GET variables passed through the URL, and could display itself appropriately by knowing which story to request from your service and which page to display. Then pagereader.php would also display navigation links by simply using $_GET variables. Google follows these types of links without difficulty.

So really, it's all a question of whether or not Joomla will interpret your php. If it will then you just need to write pagereader.php and provide it to your participating webmasters. If not, I think you should probably just stick with your iframe.

By the way, I know for certain that a Joomla module will interpret user-generated php, so possibly a Joomla module would be the way to go here. Thing is, I've never tried to position a Joomla module in the center of a Joomla page where one would expect to find the primary content. I'm not sure if that can be done or not.
Avatar of MrsCRJ

ASKER

Do you know where I can find examples of pagereader.php? Theoretically, I could have the component's main file call a pagereader file. At least I could give it a shot...
ASKER CERTIFIED SOLUTION
Avatar of MasonWolf
MasonWolf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrsCRJ

ASKER

I took MasonWolf's suggestion and I set up a test PHP file using file_get_contents to conduct some tests. Joomla performed perfectly (was able to capture and store output into a variable that could then be manipulated). However, eFiction did not behave as nicely. I did some digging, and I suspect that the issue is a problem with how it is actually programmed (i.e., it uses relative URL/URI instead of absolute - a HUGE problem).

However, I found your recommendation works in the other direction. I can get Joomla to "wrap" around eFiction using this method. From the end user's perspective, it really doesn't matter, as it will all look the same. I've got to keep playing with this (newbie here) but at least I have something that will solve my problem. Thanks!