0

Here is my code

<?php
    $url="http://www.google.co.in";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    echo $result;
?>

When I try to display webpage in div it goes full page. I want to display it only in div which I want.

It is not getting code from it's original css file. And it is not displaying images.

I want to display webpage as it is in <div id="content"> </div>

4
Contributors
14
Replies
24
Views
5 Years
Discussion Span
Last Post by vizz
Featured Replies
  • 1
    diafol 3,720   5 Years Ago

    If you include the site's navigation bar, it may play havoc with yourown, as I assume that the links will be references to your server. Could you not include an image of the site instead? Read More

0

Google uses js to apply css styles. I assume that they have relative references - if so, images and files will be expected to be found on your server, not theirs.

The Google image for example is this:

<div dir="ltr" title="Google" align="left" id="hplogo" onload="window.lol&amp;&amp;lol()" style="background:url(images/srpr/logo3w.png) no-repeat;background-size:275px 95px;height:95px;width:275px"><div nowrap="nowrap" style="color:#777;font-size:16px;font-weight:bold;position:relative;left:214px;top:70px">UK</div></div>

Notice the url(images/srpr/logo3w.png)

It's a relative reference for the Google server - not yours.

You could run a routine to prepend the rest the 'http://www.google.co.in/' to url(images...) and others with either preg_replace() or even a str_replace()

Edited by diafol

0

websites are stored in database. There are more than 1 websites.
How to display multiple websites in div one bye one?

0

What do you mean stored in a DB? Are you saying that you're storing urls or the actual html? If the latter - don't.
If you want to display live sites, you can use iframes.

<iframe src="...url..."></iframe>

However, you will not be able to show Google sites via iframe as they have a 'same origin' response header.

0

Thanks

I'm storing urls (not Google sites)

I tried with <iframe src="...url..."></iframe> but some framebreakers redirect to original site.

I think they will not work in php and div

So need solution to open website as it is in div tag

0

Like I said if you go down the cURL route, you will be at the mercy of same site file references.

Also, cURL can be quite intensive. You sure you're going to have multiple sites placed directly into your site? ALso be aware that you must have permission from the site owners to do this. If somebody ripped off some of my sites and injected them into their own, I'd be furious. Unless they asked nicely and agreed only to use it in certain ways.

If sites are using frame breakers, then I assume it's for a good reason.

Edited by diafol

0

sites submitted by site owners will displayed on advertisement site in div because iframe is not working well.

Some sites have frame breakers. It stops advertisement circle by redirecting to main site out from iframe tag. So iframe is not suitable.

Thats why I need div solution with php/curl to display website as it is in div

0

On main site there is div where I'm displaying sites for advertising purpose,

here is my latest code

 <div id="main_content">  

        <?php

        //  Load website in div using curl
            function Get_Domain_Contents($url){
                $ch = curl_init();
                $timeout = 5;
                curl_setopt($ch,CURLOPT_URL,$url);
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
                curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                $data = curl_exec($ch);
                curl_close($ch);
                return $data;   
            }

            $url = 'http://www.pastebin.com';

            $html = Get_Domain_Contents($url);

            $html = "<base href='{$url}' />" . $html;

            echo $html;

        ?>
</div>

But some websites are disturbing main sites design. Try above code with http://www.pastebin.com & http://www.google.com (use http and local domain like:- .co.in for India for google)

0

@vizz

But some websites are disturbing main sites design.

Did you include this:

// grab URL and pass it to the browser  

$output = curl_exec($ch);  

//Regular expression to excerpt the targeted portion  
preg_match('/<dl class="markets clearfix strong small">(.*)<\/dl>/is', $output, $matches);  
echo $matches[0];  

Did you read the link?

Edited by LastMitch: grammer

0

@LastMitch

yes, but little confused.

can u modify my latest code?

1

If you include the site's navigation bar, it may play havoc with yourown, as I assume that the links will be references to your server. Could you not include an image of the site instead?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.