Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 493797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:26:20+00:00 2026-05-13T05:26:20+00:00

How can I use PHP to include an external webpage? (sort of like the

  • 0

How can I use PHP to include an external webpage? (sort of like the wordpress theme preview.)

I want (X)HTML STRICT compliant code – no iFrame and preferably no javascript.

The idea is that I am making a sandbox for clients to view webpages in my controlled environment. The other thing is that the webpages being included should not be visible without the “sandbox” wrapper”.

EDIT:

According to some commentators, GoDaddy has cUrl. The next part of the question becomes – how do I strip out the headers and footers of the html in php so that just the contents of the body tag remain? I would rather use php string functions than regex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:26:21+00:00Added an answer on May 13, 2026 at 5:26 am

    Try Using Curl:

    /**
     * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
     * array containing the HTTP server response header fields and content.
     */
    function get_web_page( $url )
    {
        $options = array(
            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_USERAGENT      => "spider", // who am i
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
            CURLOPT_TIMEOUT        => 120,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        );
    
        $ch      = curl_init( $url );
        curl_setopt_array( $ch, $options );
        $content = curl_exec( $ch );
        $err     = curl_errno( $ch );
        $errmsg  = curl_error( $ch );
        $header  = curl_getinfo( $ch );
        curl_close( $ch );
    
        $header['errno']   = $err;
        $header['errmsg']  = $errmsg;
        $header['content'] = $content;
        return $header;
    }
    

    Just call that function as-is with your url and it should echo out the whole webpage into the php page.

    However, you may need to rewrite links to assets, such as stylesheets and images using some regex. (Replace “/image.jpg” with “http://mydomain.com/image.jpg“).

    Curl usually is installed on shared hosts.

    If you want to just get the page’s body, or head, you can use simplexml or regex expressions for that. (If the html is well-formed, simplexml is great for traversing the DOM).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem: I want to use PHP include to import file header_menu.html into all
Let's say I just want to use PHP include to grab HTML from another
I understand that within same folder, I can use include() function for external PHP
How can you use jQuery to include/require a different php file if window height
I can't use PHP in my HTML pages. For example, index.html . I've tried
How can I use PHP's include function to include a file and then modify
I'm trying to install the PECL extension pecl_http so that I can use PHP's
How can I use php to download an image from URL (eg: https://www.google.com/images/srpr/logo3w.png )
I'm a bit confused with this: can I use PHP variables in a pg
I have a .NET DLL containing functions that I can use in PHP. Though

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.