include another website in your page?

Discussion in 'PHP' started by mokimofiki, Feb 3, 2009.

  1. #1
    Is there any way that you can include another website within your site using php?

    Example:
    I have 2 different domains and I want to load both of them at one time split screen on a third domain can this be done? and if so how?
     
    mokimofiki, Feb 3, 2009 IP
  2. pqdrummer

    pqdrummer Peon

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Couldn't that just be done using iframes?

    
            <iframe src="http://site1.com" height="200">
            </iframe>
            <iframe src="http://site2.com" height="200">
            </iframe>
    
    Code (markup):
    Otherwise you could use the php include() function and include the specific file that you want to load from each domain.
     
    pqdrummer, Feb 3, 2009 IP
  3. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You can also use the cURL library of php to get the html from a url as a string and use it.
     
    plog, Feb 3, 2009 IP
  4. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #4
    If something does not require php, I will prefer not to use it.
     
    harrisunderwork, Feb 3, 2009 IP
  5. klm.php

    klm.php Banned

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Iframes are not a good idea to use, they are now deprecated in HTML 4.1 Strict DTD anyway.

    This is how you can do it with cURL in PHP:

    
    <?php
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://website.com");
    curl_exec($curl);
    curl_close($curl);
    ?>
    
    Code (markup):
     
    klm.php, Feb 3, 2009 IP
  6. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #6
    Curl will also break relative image urls if you try to use the above code. So you have to make them absolute too.
     
    harrisunderwork, Feb 4, 2009 IP
  7. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #7
    <iframe> methods are nice for getting around blocked server ports and disabled PHP functions/directives.

    Some servers will not allow HTTP include/require calls, you would need to try fsockopen or file_get_contents, provided that those functions aren't blocked from HTTP reading as well.

    cURL is probably the fastest server-based method from what I've seen of peoples benchmarks, but is a lot more complicated than include/require/file_get_contents because of the extra control it provides.

    Of course, there's always the chance these websites are on the same server in which case you should be able to include filesystem based paths to the pages instead of http:// based paths without many, if any, problems.
     
    joebert, Feb 4, 2009 IP
  8. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #8
    you cannot include remote webpages if allow_url_fopen is disabled
    so..curl is your best bet..
    you can get the html contents of the remote website
    into a php string and can even display it inside a div layer.
     
    vic_msn, Feb 4, 2009 IP
  9. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #9
    use html framesets
     
    hassanahmad1, Feb 4, 2009 IP
  10. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #10
    Are you being serious ?
     
    joebert, Feb 4, 2009 IP
  11. hassanahmad1

    hassanahmad1 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #11
    Do u have any doubt abt it?
    i mean this: http://www.howtocreate.co.uk/tutorials/html/framesets
    I think he needs just that:
     
    hassanahmad1, Feb 4, 2009 IP