Hello,
How can I display an external page inside the main screen of Drupal?
So for example when I click on a menu-button named google, I want to show the google-page in the right-screen (i think it's called the body). Do I need a special module?

TIA, Edwin, The Netherlands

Comments

bslade’s picture

You have to create a page with an "Input Format" type of "PHP Code", then insert the following PHP code into that page:

<?php
ob_start();
include_once "http://www.WebSiteToInclude.com/";   
$output = ob_get_contents();
ob_end_clean();
return $output;
?>

Be careful of fancy CSS styles in the included page because they can screw up the formatting of your overall Drupal page.

Just a clarification, although the Drupal.org HandbookTerminology page doesn't describe this, there are two sidebar columns that contain "blocks". The center wide column is the content column. Note that the right sidebar column doesn't necessarily show, so in that case (your case), the content column would be right column.

Ben in DC

davereplicant’s picture

Hello,

I stumbled accross this solution while trying to integrate an external site into the content area of a Drupal site.

I have followed the instructions above for creating this solution and adjusted the Input Formats to include PHP just incase that was causing my weird results.

My problem is this (please excuse me if I'm trying the impossible here)

The external website shows up in my test site using the code:

ob_start();
include_once "http://www.externalsite/index.htm";   
$output = ob_get_contents();
ob_end_clean();
return $output;

Unfortunately no graphics or interactivity is supplied with this method - instead of the graphics URL's maintaining thier original filepath such as http://www.externalsite/picture.jpg they resort to http://mysite/picture.jpg which of course doesn't host the picture and unfortunately this applies to all links on the external page also.

I'm not a programmer, I'm sure this must be blindingly obvious to some of you more experienced Drupalers.

Witht he greatest respect I have tried hard to understand where I'm going wrong here and any advice would be greatly appreciated.

Thanks in advance for your help.

www.dawnofthereplicants.com

scarins’s picture

I to need to fix the image issue, can someone please help, im not linking to google but out old site.

jspence’s picture

Did you ever find a solution to display external website in content area of drupal that didn't screw up the links of that external site? I'm using the code below and I'm running into the same problems you did.

<?php
ob_start();
include_once "http://www.externalsite/index.htm";   
$output = ob_get_contents();
ob_end_clean();
return $output;
?>

What did you to get it to work?

Thanks,
Jason

cog.rusty’s picture

I don't think so.

Try an iframe instead:
http://www.w3schools.com/tags/tag_iframe.asp

<iframe
src="http://example.com"
height="350"
width="350"
frameborder=0>
</iframe>

If what you display fits in, then the borders won't appear.

There is also something similar and more trendy, called an "object"
http://www.w3schools.com/tags/tag_object.asp

But it seems really buggy across browsers. In some cases it crashes IE6 very badly.

jsowders’s picture

Thanks. I posted a similar question yesterday. I spent several hours testing solutions and then found yours this morning. I've got a separate web server that has a lot of php programs. I didn't want to have to convert or migrate all of this code to my Drupal intranet site. This works perfectly for me.

JS

wisdom’s picture

Is there away to display external dynamic link in Drupal windows? For example the link of news feeds from other sites.

Online Business

cog.rusty’s picture

What is a dynamic link?

wisdom’s picture

A link which you do not know exactly its path at writing the code, for example a link in news feed when clicked it takes you to the source page.

Online Business

cog.rusty’s picture

I am not sure I understand. Feeds have fixed links...

Do you mean some code which produces different links dynamically? Perhaps the l()function?

http://api.drupal.org/api/function/l/5

shakethetv’s picture

yes it's possible using curl, regex the result and then output what you want in your theme.

shakethetv.com - lyrics - music

wisdom’s picture

Shakethetv would you give more explanation on how to do.

Online Business

shakethetv’s picture

yes curl is a powerfull library in php you can check those links :
fr.php.net/curl and curl.haxx.se
it must be compiled with your php installation (package for php5 : php5-curl)

here is an example how to use it :

$url = "youtube.com";
$ch = curl_init();
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_USERAGENT, '$agent');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);

this code will download the youtube.com main page.

if you want to check the result within drupal copy this code in an enable module or directy in your template with phptag function... :

function _curl_test(){
$url = "youtube.com";
$ch = curl_init();
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
//spoof browser
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_USERAGENT, '$agent');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);

return $result;

now in your template : page.tpl.php or an existing template page write this somewhere in the page :

$test = _curl_test(); echo"$test";

you will see the youtube mainpage in drupal it's just the result of the curl function.

now the regular expression :

you will need to parse the curl result in order to retrieve what you need and not just the whole page, regex will do that.

download this software http://www.radsoftware.com.au/ you will be able to test your regex with this one.

search some websites with tutorials ex: www.regular-expressions.info

need some php function:
preg_match_all
preg_match

how array in php works :
array

now quick and simple example to retrieve youtube page title :

$url = "http://www.youtube.com";
$ch = curl_init();
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7";
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_USERAGENT, '$agent');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 
$result = curl_exec($ch);
curl_close($ch);

$pattern = "#<title>(.*?)</title>#s";
preg_match_all($pattern, $result, $matches);

echo "<pre>"; print_r ($matches); echo "</pre>"; 
$youtube_title = $matches[1][0];
echo "$youtube_title"</pre>"; 

$pattern is the regular expression and $matches the result of the regex (array).

$youtube_title is the final result.

sorry for my english but i hope it will help you.

shakethetv.com - lyrics - music

igbonine’s picture

How do I adapt this solution to enable me open the external links in my menu and the news aggregator in drupal's main content area?
Thanks.

binford2k’s picture

Google's terms of service don't allow this.

wisdom’s picture

Do you mean Google penalize in search engine ranking sites who does this? Yahoo takes its news from AP and other sources and it displays it in its own page. I think what matters is the permission of the original content owner. From the point of view of user friendliness opening in the same window sometimes can be preferable.

Online Business

binford2k’s picture

I mean that if you wrap google.com in your page, their lawyers will contact you with a nice little letter.

mcpbv777’s picture

Hate to bring back an old topic but this is the only post I found that was close to what I was looking for.

My problem is rather than opening an external link inside the body, I would like to open different pages in the content column. These pages are located on the same server as the Drupal site but are separate from Drupal. For example, if my main page is www.example.com, the pages I have are located at www.example.com/pages. I tried the first solution and while it does open the page, the links and images on that page don't seem to work.

Many thanks for any advice in advance.

dman’s picture

I can't give you any support, but Here's what I did to to do that for legacy pages.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/